RegExp.h++
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __ccxx_RegExp_hxx
00024 #define __ccxx_RegExp_hxx
00025
00026 #include <commonc++/Common.h++>
00027 #include <commonc++/ParseException.h++>
00028 #include <commonc++/String.h++>
00029
00030 #include <sys/types.h>
00031
00032 namespace ccxx {
00033
00040 class COMMONCPP_API RegExpMatch
00041 {
00042 friend class RegExp;
00043
00044 public:
00045
00047 RegExpMatch()
00048 : rm_so(-1), rm_eo(-1)
00049 { }
00050
00052 inline bool isValid() const throw()
00053 { return(rm_so >= 0); }
00054
00056 inline uint_t getStartIndex() const throw()
00057 { return(rm_so >= 0 ? rm_so : 0); }
00058
00062 inline uint_t getEndIndex() const throw()
00063 { return((rm_eo >= 0) && (rm_so >= 0) ? rm_eo : 0); }
00064
00065 private:
00066
00067 int rm_so;
00068 int rm_eo;
00069 };
00070
00076 class COMMONCPP_API RegExp
00077 {
00078 public:
00079
00081 RegExp() throw();
00082
00084 RegExp(const RegExp& other) throw(ParseException);
00085
00087 ~RegExp() throw();
00088
00096 void setPattern(const char *pattern, bool caseInsensitive = false)
00097 throw(ParseException);
00098
00106 void setPattern(const String &pattern, bool caseInsensitive = false)
00107 throw(ParseException);
00108
00110 inline String getPattern() const
00111 { return(_pattern); }
00112
00114 inline String toString() const
00115 { return(getPattern()); }
00116
00123 bool match(const char *text) const throw();
00124
00131 bool match(const String &text) const throw();
00132
00141 bool match(const char *text, RegExpMatch matches[], int numMatches) const
00142 throw();
00143
00152 bool match(const String &text, RegExpMatch matches[], int numMatches)
00153 const throw();
00154
00156 RegExp& operator=(const RegExp &other);
00157
00159 inline bool isNull() const throw()
00160 { return(_pattern.isNull()); }
00161
00163 inline bool operator!() const throw()
00164 { return(_pattern.isNull()); }
00165
00171 static String escapeMeta(const String &text);
00172
00173 private:
00174
00175 String _pattern;
00176 struct
00177 {
00178 void *re_pcre;
00179 size_t re_nsub;
00180 size_t re_erroffset;
00181 } _regex;
00182 bool _compiled;
00183 };
00184
00185 };
00186
00187 #endif // __ccxx_RegExp_hxx
00188
00189