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 #ifdef BALL_HAS_BOOST_REGEX
00015 # include <boost/regex.h>
00016 #else
00017
00018 #if !defined(__GNUC__) && !defined(__KAI__) && defined(IRIX)
00019 # pragma set woff 1174
00020 #endif
00021
00022 #ifdef BALL_HAS_SYS_TYPES_H
00023 # include <sys/types.h>
00024 #endif
00025
00026 #ifdef BALL_HAS_REGEX_H
00027
00028
00029 # ifdef BALL_COMPILER_MSVC
00030 # define __STDC__ 1
00031 extern "C" {
00032 # endif
00033 # include <regex.h>
00034 # ifdef BALL_COMPILER_MSVC
00035 }
00036 # endif
00037 #endif
00038
00039 #endif
00040
00041 #if !defined(__GNUC__) && !defined(__KAI__) && defined(IRIX)
00042 # pragma reset woff 1174
00043 #endif
00044
00045 #ifndef BALL_DATATYPE_STRING_H
00046 # include <BALL/DATATYPE/string.h>
00047 #endif
00048
00049 #define BALL_REGULAR_EXPRESSION_DEFAULT_PATTERN ""
00050
00051 namespace BALL
00052 {
00056 class BALL_EXPORT RegularExpression
00057 {
00058 public:
00059
00060 BALL_CREATE(RegularExpression)
00061
00062
00065
00066
00068 static const String ALPHA;
00069
00072 static const String ALPHANUMERIC;
00073
00076 static const String REAL;
00077
00080 static const String IDENTIFIER;
00081
00084 static const String INTEGER;
00085
00088 static const String HEXADECIMAL_INTEGER;
00089
00092 static const String LOWERCASE;
00093
00096 static const String NON_ALPHA;
00097
00100 static const String NON_ALPHANUMERIC;
00101
00104 static const String NON_NUMERIC;
00105
00108 static const String NON_WHITESPACE;
00109
00112 static const String UPPERCASE;
00113
00116 static const String WHITESPACE;
00118
00122
00124 RegularExpression();
00125
00127 RegularExpression(const RegularExpression& regular_expression);
00128
00130 RegularExpression(const String& pattern, bool wildcard_pattern = false);
00131
00133 virtual ~RegularExpression();
00134
00136 virtual void clear();
00137
00139 void destroy();
00141
00145
00147 RegularExpression& operator = (const RegularExpression& expression);
00148
00150 void set(const RegularExpression& regular_expression);
00151
00153 void set(const String& pattern, bool wildcard_pattern = false);
00154
00156 void get(RegularExpression& regular_expression) const;
00158
00162
00164 const String& getPattern() const;
00165
00167 Size countSubexpressions() const;
00168
00176 static bool match(const char* text, const char* pattern,
00177 int compile_flags = 0 | REG_EXTENDED | REG_NOSUB, int execute_flags = 0)
00178 throw(Exception::NullPointer);
00179
00185 bool match(const String& text, Index from = 0, int execute_flags = 0) const
00186 throw(Exception::NullPointer, Exception::IndexUnderflow, Exception::IndexOverflow);
00187
00193 bool match(const Substring& text, Index from = 0, int execute_flags = 0) const
00194 throw(Substring::InvalidSubstring, Exception::IndexUnderflow, Exception::IndexOverflow);
00195
00200 bool match(const char* text, int execute_flags = 0) const
00201 throw(Exception::NullPointer);
00202
00208 bool find(const String& text, Substring& found,
00209 Index from = 0, int execute_flags = 0) const
00210 throw(Exception::IndexUnderflow, Exception::IndexOverflow);
00211
00218 bool find(const String& text, vector<Substring>& subexpressions,
00219 Index from = 0, int execute_flags = 0) const
00220 throw(Exception::IndexUnderflow, Exception::IndexOverflow);
00221
00223
00226
00229 bool isEmpty() const;
00230
00233 bool operator == (const RegularExpression& regular_expression) const;
00234
00237 bool operator != (const RegularExpression& regular_expression) const;
00238
00241 bool operator < (const RegularExpression& regular_expression) const;
00242
00245 bool operator <= (const RegularExpression& regular_expression) const;
00246
00249 bool operator >= (const RegularExpression& regular_expression) const;
00250
00253 bool operator > (const RegularExpression& regular_expression) const;
00254
00256
00259
00262 virtual bool isValid() const;
00263
00269 virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
00270
00272
00275
00278 BALL_EXPORT
00279 friend std::ostream& operator << (std::ostream& s, const RegularExpression& regular_expression);
00280
00283 BALL_EXPORT
00284 friend std::istream& operator >> (std::istream& s, RegularExpression& regular_expression);
00285
00287
00288 private:
00289
00290 void compilePattern_();
00291
00292 void toExtendedRegularExpression_();
00293
00294 regex_t regex_;
00295
00296 String pattern_;
00297 bool valid_pattern_;
00298 };
00299
00300 # ifndef BALL_NO_INLINE_FUNCTIONS
00301 # include <BALL/DATATYPE/regularExpression.iC>
00302 # endif
00303 }
00304
00305 #endif // BALL_DATATYPE_REGULAREXPRESSION_H