00001
00002
00003
00004
00005
00006
00007 #ifndef BALL_DATATYPE_REGULAREXPRESSION_H
00008 #define BALL_DATATYPE_REGULAREXPRESSION_H
00009
00010 #ifndef BALL_COMMON_H
00011 # include <BALL/common.h>
00012 #endif
00013
00014
00015 #if !defined(__GNUC__) && !defined(__KAI__) && defined(IRIX)
00016 # pragma set woff 1174
00017 #endif
00018
00019 #ifdef BALL_HAS_SYS_TYPES_H
00020 # include <sys/types.h>
00021 #endif
00022
00023 #ifdef BALL_HAS_REGEX_H
00024
00025
00026 # ifdef BALL_COMPILER_MSVC
00027 # define __STDC__ 1
00028 extern "C" {
00029 # endif
00030 # include <regex.h>
00031 # ifdef BALL_COMPILER_MSVC
00032 }
00033 # endif
00034 #endif
00035
00036 #if !defined(__GNUC__) && !defined(__KAI__) && defined(IRIX)
00037 # pragma reset woff 1174
00038 #endif
00039
00040 #ifndef BALL_DATATYPE_STRING_H
00041 # include <BALL/DATATYPE/string.h>
00042 #endif
00043
00044 #define BALL_REGULAR_EXPRESSION_DEFAULT_PATTERN ""
00045
00046 namespace BALL
00047 {
00051 class BALL_EXPORT RegularExpression
00052 {
00053 public:
00054
00055 BALL_CREATE(RegularExpression)
00056
00057
00060
00061
00063 static const String ALPHA;
00064
00067 static const String ALPHANUMERIC;
00068
00071 static const String REAL;
00072
00075 static const String IDENTIFIER;
00076
00079 static const String INTEGER;
00080
00083 static const String HEXADECIMAL_INTEGER;
00084
00087 static const String LOWERCASE;
00088
00091 static const String NON_ALPHA;
00092
00095 static const String NON_ALPHANUMERIC;
00096
00099 static const String NON_NUMERIC;
00100
00103 static const String NON_WHITESPACE;
00104
00107 static const String UPPERCASE;
00108
00111 static const String WHITESPACE;
00113
00117
00119 RegularExpression();
00120
00122 RegularExpression(const RegularExpression& regular_expression);
00123
00125 RegularExpression(const String& pattern, bool wildcard_pattern = false);
00126
00128 virtual ~RegularExpression();
00129
00131 virtual void clear();
00132
00134 void destroy();
00136
00140
00142 RegularExpression& operator = (const RegularExpression& expression);
00143
00145 void set(const RegularExpression& regular_expression);
00146
00148 void set(const String& pattern, bool wildcard_pattern = false);
00149
00151 void get(RegularExpression& regular_expression) const;
00153
00157
00159 const String& getPattern() const;
00160
00162 Size countSubexpressions() const;
00163
00171 static bool match(const char* text, const char* pattern,
00172 int compile_flags = 0 | REG_EXTENDED | REG_NOSUB, int execute_flags = 0)
00173 throw(Exception::NullPointer);
00174
00180 bool match(const String& text, Index from = 0, int execute_flags = 0) const
00181 throw(Exception::NullPointer, Exception::IndexUnderflow, Exception::IndexOverflow);
00182
00188 bool match(const Substring& text, Index from = 0, int execute_flags = 0) const
00189 throw(Substring::InvalidSubstring, Exception::IndexUnderflow, Exception::IndexOverflow);
00190
00195 bool match(const char* text, int execute_flags = 0) const
00196 throw(Exception::NullPointer);
00197
00203 bool find(const String& text, Substring& found,
00204 Index from = 0, int execute_flags = 0) const
00205 throw(Exception::IndexUnderflow, Exception::IndexOverflow);
00206
00213 bool find(const String& text, vector<Substring>& subexpressions,
00214 Index from = 0, int execute_flags = 0) const
00215 throw(Exception::IndexUnderflow, Exception::IndexOverflow);
00216
00218
00221
00224 bool isEmpty() const;
00225
00228 bool operator == (const RegularExpression& regular_expression) const;
00229
00232 bool operator != (const RegularExpression& regular_expression) const;
00233
00236 bool operator < (const RegularExpression& regular_expression) const;
00237
00240 bool operator <= (const RegularExpression& regular_expression) const;
00241
00244 bool operator >= (const RegularExpression& regular_expression) const;
00245
00248 bool operator > (const RegularExpression& regular_expression) const;
00249
00251
00254
00257 virtual bool isValid() const;
00258
00264 virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
00265
00267
00270
00273 BALL_EXPORT
00274 friend std::ostream& operator << (std::ostream& s, const RegularExpression& regular_expression);
00275
00278 BALL_EXPORT
00279 friend std::istream& operator >> (std::istream& s, RegularExpression& regular_expression);
00280
00282
00283 private:
00284
00285 void compilePattern_();
00286
00287 void toExtendedRegularExpression_();
00288
00289 regex_t regex_;
00290
00291 String pattern_;
00292 bool valid_pattern_;
00293 };
00294
00295 # ifndef BALL_NO_INLINE_FUNCTIONS
00296 # include <BALL/DATATYPE/regularExpression.iC>
00297 # endif
00298 }
00299
00300 #endif // BALL_DATATYPE_REGULAREXPRESSION_H