00001 #ifndef CLASSLIB_REGEXP_H
00002 # define CLASSLIB_REGEXP_H
00003
00004
00005
00006 # include "classlib/utils/RegexpMatch.h"
00007 # include <utility>
00008 # include <string>
00009 # include <vector>
00010 # include <list>
00011
00012 namespace lat {
00013
00014
00015
00016
00017
00018
00019
00020 class Regexp
00021 {
00022 public:
00024
00025 static const Regexp rxwhite;
00026 static const Regexp rxint;
00027 static const Regexp rxdouble;
00028
00029 static const Regexp rxalpha;
00030 static const Regexp rxlowercase;
00031 static const Regexp rxuppercase;
00032 static const Regexp rxalphanum;
00033 static const Regexp rxidentifier;
00034
00036
00037 enum Syntax {
00038 POSIXBasic = 0x0001,
00039 POSIXExtended = 0x0002,
00040 Perl = 0x0003,
00041 Wildcard = 0x0004
00042 };
00043
00045
00046 enum Options {
00047 AnchorAtStart = 0x0010,
00048 IgnoreCase = 0x0020,
00049 DollarAtEndOnly = 0x0040,
00050 DotMatchesAll = 0x0080,
00051 Extended = 0x0100,
00052 MultiLine = 0x0200,
00053 Minimal = 0x0400,
00054
00055
00056
00057 StandardLocale = 0x2000
00058 };
00059
00061
00062 enum MatchOptions {
00077 MatchNotBOL = 0x01,
00078
00091 MatchOffsetBOL = 0x02,
00092
00100 MatchNotEOL = 0x04,
00101
00108 MatchNoEmpty = 0x08,
00109
00111 MatchAnchored = 0x10,
00112
00114 MatchAll = 0x20,
00115
00120 MatchContinue = 0x40
00121 };
00122
00124 Regexp (void);
00125 Regexp (const std::string &pat, unsigned options = 0, Syntax s = Perl);
00126
00127 Regexp (const Regexp &x);
00128 Regexp &operator= (const Regexp &x);
00129 Regexp &operator= (const std::string &x);
00130 ~Regexp (void);
00131
00132 bool operator== (const Regexp &x) const;
00133 bool operator!= (const Regexp &x) const;
00134
00135 static std::string escape (const std::string &text);
00136
00137 Syntax syntax (void) const;
00138 bool empty (void) const;
00139 bool valid (void) const;
00140
00141 int errorOffset (void) const;
00142 const char * errorMessage (void) const;
00143 void clearError (void);
00144
00145 unsigned options (void) const;
00146 void setOptions (unsigned value);
00147 void enableOptions (unsigned mask);
00148 void disableOptions (unsigned mask);
00149
00150 std::string pattern (void) const;
00151 void setPattern (const std::string &pat);
00152
00153 bool compile (bool force = false);
00154 void study (void);
00155
00156 bool exactMatch (const char *s) const;
00157 bool exactMatch (const std::string &s) const;
00158
00159 bool match (const char *s, int offset = 0,
00160 int flags = 0, RegexpMatch *result = 0) const;
00161 bool match (const std::string &s, int offset = 0,
00162 int flags = 0, RegexpMatch *result = 0) const;
00163
00164 int search (const char *s, int offset = 0,
00165 int flags = 0, RegexpMatch *result = 0) const;
00166 int search (const std::string &s, int offset = 0,
00167 int flags = 0, RegexpMatch *result = 0) const;
00168
00169 int rsearch (const char *s, int offset = -1,
00170 int flags = 0, RegexpMatch *result = 0) const;
00171 int rsearch (const std::string &s, int offset = -1,
00172 int flags = 0, RegexpMatch *result = 0) const;
00173
00174 protected:
00175 void uncompile (void);
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 private:
00188 static const int SyntaxMask = 0x000F;
00189 struct Rep;
00190 struct PCRERep;
00191 struct POSIXRep;
00192
00193 std::string m_pattern;
00194 unsigned m_options;
00195 Rep *m_rep;
00196 };
00197
00198
00199
00200
00201 }
00202 #endif // CLASSLIB_REGEXP_H