BALL  1.5.0
regularExpression.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_DATATYPE_REGULAREXPRESSION_H
6 #define BALL_DATATYPE_REGULAREXPRESSION_H
7 
8 #ifndef BALL_COMMON_H
9 # include <BALL/common.h>
10 #endif
11 
12 #include <boost/regex.h>
13 
14 #if !defined(__GNUC__) && !defined(__KAI__) && defined(IRIX)
15 # pragma reset woff 1174
16 #endif
17 
18 #ifndef BALL_DATATYPE_STRING_H
19 # include <BALL/DATATYPE/string.h>
20 #endif
21 
22 #define BALL_REGULAR_EXPRESSION_DEFAULT_PATTERN ""
23 
24 namespace BALL
25 {
30  {
31  public:
32 
34 
35 
38 
39 
41  static const String ALPHA;
42 
45  static const String ALPHANUMERIC;
46 
49  static const String REAL;
50 
53  static const String IDENTIFIER;
54 
57  static const String INTEGER;
58 
61  static const String HEXADECIMAL_INTEGER;
62 
65  static const String LOWERCASE;
66 
69  static const String NON_ALPHA;
70 
73  static const String NON_ALPHANUMERIC;
74 
77  static const String NON_NUMERIC;
78 
81  static const String NON_WHITESPACE;
82 
85  static const String UPPERCASE;
86 
89  static const String WHITESPACE;
91 
95 
98 
100  RegularExpression(const RegularExpression& regular_expression);
101 
103  RegularExpression(const String& pattern, bool wildcard_pattern = false);
104 
106  virtual ~RegularExpression();
107 
109  virtual void clear();
110 
112  void destroy();
114 
118 
120  RegularExpression& operator = (const RegularExpression& expression);
121 
123  void set(const RegularExpression& regular_expression);
124 
126  void set(const String& pattern, bool wildcard_pattern = false);
127 
129  void get(RegularExpression& regular_expression) const;
131 
135 
137  const String& getPattern() const;
138 
140  Size countSubexpressions() const;
141 
149  static bool match(const char* text, const char* pattern,
150  int compile_flags = 0 | REG_EXTENDED | REG_NOSUB, int execute_flags = 0);
151 
159  bool match(const String& text, Index from = 0, int execute_flags = 0) const;
160 
169  bool match(const Substring& text, Index from = 0, int execute_flags = 0) const;
170 
176  bool match(const char* text, int execute_flags = 0) const;
177 
185  bool find(const String& text, Substring& found,
186  Index from = 0, int execute_flags = 0) const;
187 
196  bool find(const String& text, vector<Substring>& subexpressions,
197  Index from = 0, int execute_flags = 0) const;
198 
200 
203 
206  bool isEmpty() const;
207 
210  bool operator == (const RegularExpression& regular_expression) const;
211 
214  bool operator != (const RegularExpression& regular_expression) const;
215 
218  bool operator < (const RegularExpression& regular_expression) const;
219 
222  bool operator <= (const RegularExpression& regular_expression) const;
223 
226  bool operator >= (const RegularExpression& regular_expression) const;
227 
230  bool operator > (const RegularExpression& regular_expression) const;
231 
233 
236 
239  virtual bool isValid() const;
240 
246  virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
247 
249 
252 
256  friend std::ostream& operator << (std::ostream& s, const RegularExpression& regular_expression);
257 
261  friend std::istream& operator >> (std::istream& s, RegularExpression& regular_expression);
262 
264 
265  private:
266 
267  void compilePattern_();
268 
269  void toExtendedRegularExpression_();
270 
271  regex_t regex_;
272 
273  String pattern_;
274  bool valid_pattern_;
275  };
276 
277 # ifndef BALL_NO_INLINE_FUNCTIONS
278 # include <BALL/DATATYPE/regularExpression.iC>
279 # endif
280 } // namespace BALL
281 
282 #endif // BALL_DATATYPE_REGULAREXPRESSION_H
STL namespace.
#define BALL_EXPORT
Definition: COMMON/global.h:50
Definition: constants.h:12
#define BALL_CREATE(name)
Definition: create.h:62