File indexing completed on 2024-05-18 08:30:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 #ifndef _PCRECPPARG_H
0033 #define _PCRECPPARG_H
0034
0035 #include <stdlib.h> // for NULL
0036 #include <string>
0037
0038 #include <pcre.h>
0039
0040 namespace pcrecpp {
0041
0042 class StringPiece;
0043
0044
0045
0046
0047 template <class T>
0048 class _RE_MatchObject {
0049 public:
0050 static inline bool Parse(const char* str, int n, void* dest) {
0051 if (dest == NULL) return true;
0052 T* object = reinterpret_cast<T*>(dest);
0053 return object->ParseFrom(str, n);
0054 }
0055 };
0056
0057 class PCRECPP_EXP_DEFN Arg {
0058 public:
0059
0060 Arg();
0061
0062
0063 Arg(void*);
0064
0065 typedef bool (*Parser)(const char* str, int n, void* dest);
0066
0067
0068 #define PCRE_MAKE_PARSER(type,name) \
0069 Arg(type* p) : arg_(p), parser_(name) { } \
0070 Arg(type* p, Parser parser) : arg_(p), parser_(parser) { }
0071
0072
0073 PCRE_MAKE_PARSER(char, parse_char);
0074 PCRE_MAKE_PARSER(unsigned char, parse_uchar);
0075 PCRE_MAKE_PARSER(short, parse_short);
0076 PCRE_MAKE_PARSER(unsigned short, parse_ushort);
0077 PCRE_MAKE_PARSER(int, parse_int);
0078 PCRE_MAKE_PARSER(unsigned int, parse_uint);
0079 PCRE_MAKE_PARSER(long, parse_long);
0080 PCRE_MAKE_PARSER(unsigned long, parse_ulong);
0081 #if 1
0082 PCRE_MAKE_PARSER(long long, parse_longlong);
0083 #endif
0084 #if 1
0085 PCRE_MAKE_PARSER(unsigned long long, parse_ulonglong);
0086 #endif
0087 PCRE_MAKE_PARSER(float, parse_float);
0088 PCRE_MAKE_PARSER(double, parse_double);
0089 PCRE_MAKE_PARSER(std::string, parse_string);
0090 PCRE_MAKE_PARSER(StringPiece, parse_stringpiece);
0091
0092 #undef PCRE_MAKE_PARSER
0093
0094
0095 template <class T> Arg(T*, Parser parser);
0096
0097 template <class T> Arg(T* p)
0098 : arg_(p), parser_(_RE_MatchObject<T>::Parse) {
0099 }
0100
0101
0102 bool Parse(const char* str, int n) const;
0103
0104 private:
0105 void* arg_;
0106 Parser parser_;
0107
0108 static bool parse_null (const char* str, int n, void* dest);
0109 static bool parse_char (const char* str, int n, void* dest);
0110 static bool parse_uchar (const char* str, int n, void* dest);
0111 static bool parse_float (const char* str, int n, void* dest);
0112 static bool parse_double (const char* str, int n, void* dest);
0113 static bool parse_string (const char* str, int n, void* dest);
0114 static bool parse_stringpiece (const char* str, int n, void* dest);
0115
0116 #define PCRE_DECLARE_INTEGER_PARSER(name) \
0117 private: \
0118 static bool parse_ ## name(const char* str, int n, void* dest); \
0119 static bool parse_ ## name ## _radix( \
0120 const char* str, int n, void* dest, int radix); \
0121 public: \
0122 static bool parse_ ## name ## _hex(const char* str, int n, void* dest); \
0123 static bool parse_ ## name ## _octal(const char* str, int n, void* dest); \
0124 static bool parse_ ## name ## _cradix(const char* str, int n, void* dest)
0125
0126 PCRE_DECLARE_INTEGER_PARSER(short);
0127 PCRE_DECLARE_INTEGER_PARSER(ushort);
0128 PCRE_DECLARE_INTEGER_PARSER(int);
0129 PCRE_DECLARE_INTEGER_PARSER(uint);
0130 PCRE_DECLARE_INTEGER_PARSER(long);
0131 PCRE_DECLARE_INTEGER_PARSER(ulong);
0132 PCRE_DECLARE_INTEGER_PARSER(longlong);
0133 PCRE_DECLARE_INTEGER_PARSER(ulonglong);
0134
0135 #undef PCRE_DECLARE_INTEGER_PARSER
0136 };
0137
0138 inline Arg::Arg() : arg_(NULL), parser_(parse_null) { }
0139 inline Arg::Arg(void* p) : arg_(p), parser_(parse_null) { }
0140
0141 inline bool Arg::Parse(const char* str, int n) const {
0142 return (*parser_)(str, n, arg_);
0143 }
0144
0145
0146 #define MAKE_INTEGER_PARSER(type, name) \
0147 inline Arg Hex(type* ptr) { \
0148 return Arg(ptr, Arg::parse_ ## name ## _hex); } \
0149 inline Arg Octal(type* ptr) { \
0150 return Arg(ptr, Arg::parse_ ## name ## _octal); } \
0151 inline Arg CRadix(type* ptr) { \
0152 return Arg(ptr, Arg::parse_ ## name ## _cradix); }
0153
0154 MAKE_INTEGER_PARSER(short, short)
0155 MAKE_INTEGER_PARSER(unsigned short, ushort)
0156 MAKE_INTEGER_PARSER(int, int)
0157 MAKE_INTEGER_PARSER(unsigned int, uint)
0158 MAKE_INTEGER_PARSER(long, long)
0159 MAKE_INTEGER_PARSER(unsigned long, ulong)
0160 #if 1
0161 MAKE_INTEGER_PARSER(long long, longlong)
0162 #endif
0163 #if 1
0164 MAKE_INTEGER_PARSER(unsigned long long, ulonglong)
0165 #endif
0166
0167 #undef PCRE_IS_SET
0168 #undef PCRE_SET_OR_CLEAR
0169 #undef MAKE_INTEGER_PARSER
0170
0171 }
0172
0173
0174 #endif