BALL  1.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #ifdef BALL_HAS_BOOST_REGEX
13 # include <boost/regex.h>
14 #else
15 // for SGI CC: turn of warnings #1174: function "regcomp" was declared but never referenced
16 #if !defined(__GNUC__) && !defined(__KAI__) && defined(IRIX)
17 # pragma set woff 1174
18 #endif
19 
20 #ifdef BALL_HAS_SYS_TYPES_H
21 # include <sys/types.h>
22 #endif
23 
24 #ifdef BALL_HAS_REGEX_H
25  // make sure __STDC__ is set when including the
26  // GNU regex headers under Windows
27 # ifdef BALL_COMPILER_MSVC
28 # define __STDC__ 1
29  extern "C" {
30 # endif
31 # include <regex.h>
32 # ifdef BALL_COMPILER_MSVC
33  }
34 # endif
35 #endif
36 
37 #endif
38 
39 #if !defined(__GNUC__) && !defined(__KAI__) && defined(IRIX)
40 # pragma reset woff 1174
41 #endif
42 
43 #ifndef BALL_DATATYPE_STRING_H
44 # include <BALL/DATATYPE/string.h>
45 #endif
46 
47 #define BALL_REGULAR_EXPRESSION_DEFAULT_PATTERN ""
48 
49 namespace BALL
50 {
55  {
56  public:
57 
59 
60 
63 
64 
66  static const String ALPHA;
67 
70  static const String ALPHANUMERIC;
71 
74  static const String REAL;
75 
78  static const String IDENTIFIER;
79 
82  static const String INTEGER;
83 
86  static const String HEXADECIMAL_INTEGER;
87 
90  static const String LOWERCASE;
91 
94  static const String NON_ALPHA;
95 
98  static const String NON_ALPHANUMERIC;
99 
102  static const String NON_NUMERIC;
103 
106  static const String NON_WHITESPACE;
107 
110  static const String UPPERCASE;
111 
114  static const String WHITESPACE;
116 
120 
123 
125  RegularExpression(const RegularExpression& regular_expression);
126 
128  RegularExpression(const String& pattern, bool wildcard_pattern = false);
129 
131  virtual ~RegularExpression();
132 
134  virtual void clear();
135 
137  void destroy();
139 
143 
145  RegularExpression& operator = (const RegularExpression& expression);
146 
148  void set(const RegularExpression& regular_expression);
149 
151  void set(const String& pattern, bool wildcard_pattern = false);
152 
154  void get(RegularExpression& regular_expression) const;
156 
160 
162  const String& getPattern() const;
163 
165  Size countSubexpressions() const;
166 
174  static bool match(const char* text, const char* pattern,
175  int compile_flags = 0 | REG_EXTENDED | REG_NOSUB, int execute_flags = 0);
176 
184  bool match(const String& text, Index from = 0, int execute_flags = 0) const;
185 
194  bool match(const Substring& text, Index from = 0, int execute_flags = 0) const;
195 
201  bool match(const char* text, int execute_flags = 0) const;
202 
210  bool find(const String& text, Substring& found,
211  Index from = 0, int execute_flags = 0) const;
212 
221  bool find(const String& text, vector<Substring>& subexpressions,
222  Index from = 0, int execute_flags = 0) const;
223 
225 
228 
231  bool isEmpty() const;
232 
235  bool operator == (const RegularExpression& regular_expression) const;
236 
239  bool operator != (const RegularExpression& regular_expression) const;
240 
243  bool operator < (const RegularExpression& regular_expression) const;
244 
247  bool operator <= (const RegularExpression& regular_expression) const;
248 
251  bool operator >= (const RegularExpression& regular_expression) const;
252 
255  bool operator > (const RegularExpression& regular_expression) const;
256 
258 
261 
264  virtual bool isValid() const;
265 
271  virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
272 
274 
277 
281  friend std::ostream& operator << (std::ostream& s, const RegularExpression& regular_expression);
282 
286  friend std::istream& operator >> (std::istream& s, RegularExpression& regular_expression);
287 
289 
290  private:
291 
292  void compilePattern_();
293 
294  void toExtendedRegularExpression_();
295 
296  regex_t regex_;
297 
298  String pattern_;
299  bool valid_pattern_;
300  };
301 
302 # ifndef BALL_NO_INLINE_FUNCTIONS
303 # include <BALL/DATATYPE/regularExpression.iC>
304 # endif
305 } // namespace BALL
306 
307 #endif // BALL_DATATYPE_REGULAREXPRESSION_H