00001
00002
00003
00004
00005 #ifndef BALL_DATATYPE_REGULAREXPRESSION_H
00006 #define BALL_DATATYPE_REGULAREXPRESSION_H
00007
00008 #ifndef BALL_COMMON_H
00009 # include <BALL/common.h>
00010 #endif
00011
00012 #ifdef BALL_HAS_BOOST_REGEX
00013 # include <boost/regex.h>
00014 #else
00015
00016 #if !defined(__GNUC__) && !defined(__KAI__) && defined(IRIX)
00017 # pragma set woff 1174
00018 #endif
00019
00020 #ifdef BALL_HAS_SYS_TYPES_H
00021 # include <sys/types.h>
00022 #endif
00023
00024 #ifdef BALL_HAS_REGEX_H
00025
00026
00027 # ifdef BALL_COMPILER_MSVC
00028 # define __STDC__ 1
00029 extern "C" {
00030 # endif
00031 # include <regex.h>
00032 # ifdef BALL_COMPILER_MSVC
00033 }
00034 # endif
00035 #endif
00036
00037 #endif
00038
00039 #if !defined(__GNUC__) && !defined(__KAI__) && defined(IRIX)
00040 # pragma reset woff 1174
00041 #endif
00042
00043 #ifndef BALL_DATATYPE_STRING_H
00044 # include <BALL/DATATYPE/string.h>
00045 #endif
00046
00047 #define BALL_REGULAR_EXPRESSION_DEFAULT_PATTERN ""
00048
00049 namespace BALL
00050 {
00054 class BALL_EXPORT RegularExpression
00055 {
00056 public:
00057
00058 BALL_CREATE(RegularExpression)
00059
00060
00063
00064
00066 static const String ALPHA;
00067
00070 static const String ALPHANUMERIC;
00071
00074 static const String REAL;
00075
00078 static const String IDENTIFIER;
00079
00082 static const String INTEGER;
00083
00086 static const String HEXADECIMAL_INTEGER;
00087
00090 static const String LOWERCASE;
00091
00094 static const String NON_ALPHA;
00095
00098 static const String NON_ALPHANUMERIC;
00099
00102 static const String NON_NUMERIC;
00103
00106 static const String NON_WHITESPACE;
00107
00110 static const String UPPERCASE;
00111
00114 static const String WHITESPACE;
00116
00120
00122 RegularExpression();
00123
00125 RegularExpression(const RegularExpression& regular_expression);
00126
00128 RegularExpression(const String& pattern, bool wildcard_pattern = false);
00129
00131 virtual ~RegularExpression();
00132
00134 virtual void clear();
00135
00137 void destroy();
00139
00143
00145 RegularExpression& operator = (const RegularExpression& expression);
00146
00148 void set(const RegularExpression& regular_expression);
00149
00151 void set(const String& pattern, bool wildcard_pattern = false);
00152
00154 void get(RegularExpression& regular_expression) const;
00156
00160
00162 const String& getPattern() const;
00163
00165 Size countSubexpressions() const;
00166
00174 static bool match(const char* text, const char* pattern,
00175 int compile_flags = 0 | REG_EXTENDED | REG_NOSUB, int execute_flags = 0);
00176
00184 bool match(const String& text, Index from = 0, int execute_flags = 0) const;
00185
00194 bool match(const Substring& text, Index from = 0, int execute_flags = 0) const;
00195
00201 bool match(const char* text, int execute_flags = 0) const;
00202
00210 bool find(const String& text, Substring& found,
00211 Index from = 0, int execute_flags = 0) const;
00212
00221 bool find(const String& text, vector<Substring>& subexpressions,
00222 Index from = 0, int execute_flags = 0) const;
00223
00225
00228
00231 bool isEmpty() const;
00232
00235 bool operator == (const RegularExpression& regular_expression) const;
00236
00239 bool operator != (const RegularExpression& regular_expression) const;
00240
00243 bool operator < (const RegularExpression& regular_expression) const;
00244
00247 bool operator <= (const RegularExpression& regular_expression) const;
00248
00251 bool operator >= (const RegularExpression& regular_expression) const;
00252
00255 bool operator > (const RegularExpression& regular_expression) const;
00256
00258
00261
00264 virtual bool isValid() const;
00265
00271 virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
00272
00274
00277
00280 BALL_EXPORT
00281 friend std::ostream& operator << (std::ostream& s, const RegularExpression& regular_expression);
00282
00285 BALL_EXPORT
00286 friend std::istream& operator >> (std::istream& s, RegularExpression& regular_expression);
00287
00289
00290 private:
00291
00292 void compilePattern_();
00293
00294 void toExtendedRegularExpression_();
00295
00296 regex_t regex_;
00297
00298 String pattern_;
00299 bool valid_pattern_;
00300 };
00301
00302 # ifndef BALL_NO_INLINE_FUNCTIONS
00303 # include <BALL/DATATYPE/regularExpression.iC>
00304 # endif
00305 }
00306
00307 #endif // BALL_DATATYPE_REGULAREXPRESSION_H