File: regularExpression.h

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-11.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 239,928 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; javascript: 164; makefile: 88
file content (282 lines) | stat: -rw-r--r-- 6,695 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#ifndef BALL_DATATYPE_REGULAREXPRESSION_H
#define BALL_DATATYPE_REGULAREXPRESSION_H

#ifndef BALL_COMMON_H
#	include <BALL/common.h>
#endif

#include <boost/regex.h>

#if !defined(__GNUC__) && !defined(__KAI__) && defined(IRIX)
#	pragma reset woff 1174
#endif

#ifndef BALL_DATATYPE_STRING_H
#	include <BALL/DATATYPE/string.h>
#endif

#define BALL_REGULAR_EXPRESSION_DEFAULT_PATTERN   ""

namespace BALL 
{
	/**	Regular expression class
    	\ingroup  DatatypeMiscellaneous
	*/
	class BALL_EXPORT RegularExpression
	{
		public:

		BALL_CREATE(RegularExpression)

		/**	@name	String constants 
		*/
		//@{
			
		/**	alphabetic letters.
		*/
		static const String ALPHA;

		/**	alphanumeric letters
		*/
		static const String ALPHANUMERIC;

		/**	real numbers
		*/
		static const String REAL;

		/** identifier characters
		*/
		static const String IDENTIFIER;

		/** integer characters
		*/
		static const String INTEGER;

		/** hexadecimal and integer characters
		*/
		static const String HEXADECIMAL_INTEGER;

		/** lowercase letters
		*/
		static const String LOWERCASE;

		/** non alphabetic characters
		*/
		static const String NON_ALPHA;

		/** non alphanumeric characters
		*/
		static const String NON_ALPHANUMERIC;

		/** non numeric characters
		*/
		static const String NON_NUMERIC;

		/** non whitespace charcters
		*/
		static const String NON_WHITESPACE;

		/**	uppercase letters.
		*/
		static const String UPPERCASE;

		/** whitespace characters.
		*/
		static const String WHITESPACE;
		//@}

		/**	@name	Constructors and Destructors 
		*/
		//@{
			
		///	Default constructor
		RegularExpression();

		///	Copy constructor
		RegularExpression(const RegularExpression& regular_expression);

		///
		RegularExpression(const String& pattern, bool wildcard_pattern = false);

		///	Destructor
		virtual ~RegularExpression();

		///	Reset the object attributes to their default values
		virtual void clear();

		///	Destroy the instance
		void destroy();
		//@}

		/**	@name	Assignment
		*/
		//@{

		/// Assignment operator
		RegularExpression& operator = (const RegularExpression& expression);

		///	Assign from another instance
		void set(const RegularExpression& regular_expression);

		///	Assign from a string
		void set(const String& pattern, bool wildcard_pattern = false);

		///	Assign to another instance
		void get(RegularExpression& regular_expression) const;
		//@}

		/**	@name	Accessors
		*/
		//@{

		///	Get the expression pattern.
		const String& getPattern() const;

		///	Count subexpressions.
		Size countSubexpressions() const;

		/**	Match a text with a given pattern.
		 *	@param text to process
		 *	@param pattern to compare with
		 *	@param compile_flags ?????
		 *	@param execute_flags ?????
		 *	@exception NullPointer if <tt>text</tt> or <tt>pattern</tt> are NULL
		 */
		static bool match(const char* text, const char* pattern,
											int compile_flags = 0 | REG_EXTENDED | REG_NOSUB, int execute_flags = 0);
		
		/**	Match a text with this regular expression.
		 *	@param text to process
		 *	@param from index in the string to start the matching
		 *	@param execute_flags ?????
		 *  @throw Exception::IndexUnderflow if from < 0
		 *  @throw Exception::IndexOverflow if from > text.size()
		 */
		bool match(const String& text, Index from = 0, int execute_flags = 0) const;
	
		/**	Match a substring with this regular expression.
		 *	@param text to process
		 *	@param from index in the substring to start the matching
		 *	@param execute_flags ?????
		 *  @throw Exception::InvalidSubstring if text is invalid
		 *  @throw Exception::IndexUnderflow if from < 0
		 *  @throw Exception::IndexOverflow if from > text.size()
		 */
		bool match(const Substring& text, Index from = 0, int execute_flags = 0) const;
	
		/**	Match a C-String with this regular expression.
		 *	@param text to process
		 *	@param execute_flags ?????
		 *	@exception NullPointer if <tt>text</tt> is NULL
		 */
		bool match(const char* text, int execute_flags = 0) const;
	
		/**	Find this expression in a string
		 *	@param from index in the string to start the matching
		 *	@param found the result is stored as a substring here
		 *	@param execute_flags ?????
		 *  @throw Exception::IndexUnderflow if from < 0
		 *  @throw Exception::IndexOverflow if from >= text.size()
		 */
		bool find(const String& text, Substring& found,
							Index from = 0, int execute_flags = 0) const;
			
		/**	Find this expression in a string
		 *	@param text to process
		 *	@param subexpressions the results are stored here
		 *	@param from index in the string to start the matching		
		 *	@param execute_flags ?????
		 *  @throw Exception::IndexUnderflow if from < 0
		 *  @throw Exception::IndexOverflow if from >= text.size()
		 */
		bool find(const String& text, vector<Substring>& subexpressions,
							Index from = 0, int execute_flags = 0) const;
						
		//@}
		/**	@name	Predicates
		*/
		//@{

		/**	Test if expression is empty.
		*/
		bool isEmpty() const;

		/**	Equality operator
		*/
		bool operator == (const RegularExpression& regular_expression) const;

		/**	Inequality operator
		*/
		bool operator != (const RegularExpression& regular_expression) const;

		/**	Less operator
		*/
		bool operator < (const RegularExpression& regular_expression) const;

		/**	Less or equal operator
		*/
		bool operator <= (const RegularExpression& regular_expression) const;

		/**	Greater or equal operator
		*/
		bool operator >= (const RegularExpression& regular_expression) const;

		/**	Greater operator
		*/
		bool operator > (const RegularExpression& regular_expression) const;

		//@}
		/**	@name	Debugging and Diagnostics
		*/
		//@{

		/**	Test if instance is valid.
		*/
		virtual bool isValid() const;

		/**	Dump this instance to an ostream
				depth is normaly just used for internal use.
				@param s the ostream, default is the standard output
				@param depth the indentation depth of the output
		*/
		virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;

		//@}
		/**	@name Storers
		*/
		//@{

		/**	output operator
		*/
		BALL_EXPORT
		friend std::ostream& operator << (std::ostream& s, const RegularExpression& regular_expression);

		/**	input operator
		*/
		BALL_EXPORT
		friend std::istream& operator >> (std::istream& s, RegularExpression& regular_expression);

		//@}
		
		private:

		void compilePattern_();

		void toExtendedRegularExpression_();

		regex_t regex_;
		
		String 	pattern_;
		bool 		valid_pattern_;
	};

#	ifndef BALL_NO_INLINE_FUNCTIONS
#		include <BALL/DATATYPE/regularExpression.iC>
#	endif
} // namespace BALL

#endif // BALL_DATATYPE_REGULAREXPRESSION_H