DCL 4.0
Loading...
Searching...
No Matches
Regex Class Reference

#include <Regex.h>

Classes

class  MatchResults

Public Types

enum  CompileFlags { ICASE = regex_icase , NOSUBS = regex_nosubs , NEWLINE = regex_newline }
enum  MatchFlags { NOTBOL = regex_not_bol , NOTEOL = regex_not_eol }

Public Member Functions

 Regex ()
 ~Regex ()
 Regex (const wchar_t *_pattern, size_t _n, unsigned int _flags=0) __DCL_THROWS1(RegexException *)
void compile (const wchar_t *_pattern, size_t _n, unsigned int _flags=0) __DCL_THROWS1(RegexException *)
bool search (const wchar_t *_begin, const wchar_t *_end, unsigned int _flags=0) __DCL_THROWS1(RegexException *)
bool search (const wchar_t *_begin, const wchar_t *_end, MatchResults &_results, unsigned int _flags=0) __DCL_THROWS1(RegexException *)
bool match (const wchar_t *_begin, const wchar_t *_end, unsigned int _flags) __DCL_THROWS1(RegexException *)
bool match (const wchar_t *_begin, const wchar_t *_end, MatchResults &_results, unsigned int _flags=0) __DCL_THROWS1(RegexException *)
 Regex (const String &_pattern, unsigned int _flags=0) __DCL_THROWS1(RegexException *)
void compile (const String &_pattern, unsigned int _flags=0) __DCL_THROWS1(RegexException *)
bool search (const String &_string, unsigned int _flags=0) __DCL_THROWS1(RegexException *)
bool search (const String &_string, MatchResults &_results, unsigned int _flags=0) __DCL_THROWS1(RegexException *)
bool match (const String &_string, unsigned int _flags=0) __DCL_THROWS1(RegexException *)
bool match (const String &_string, MatchResults &_results, unsigned int _flags=0) __DCL_THROWS1(RegexException *)
String replace (const String &_string, const String &_replacement, size_t _limit=(size_t) -1) __DCL_THROWS1(RegexException *)
size_t split (const wchar_t *_begin, const wchar_t *_end, StringArray &_results, size_t _limit=(size_t) -1) __DCL_THROWS1(RegexException *)
size_t split (const String &_string, StringArray &_results, size_t _limit=(size_t) -1) __DCL_THROWS1(RegexException *)

Static Public Member Functions

static bool test (const wchar_t *_regex, const wchar_t *_string, bool _icase=false) __DCL_THROWS1(RegexException *)
static bool test (const char *_regex, const char *_string, bool _icase=false) __DCL_THROWS1(RegexException *)

Detailed Description

Definition at line 31 of file Regex.h.

Member Enumeration Documentation

◆ CompileFlags

Enumerator
ICASE 
NOSUBS 
NEWLINE 

Definition at line 34 of file Regex.h.

34 {
38 };
@ regex_icase
Definition _regex.h:18
@ regex_newline
Definition _regex.h:20
@ regex_nosubs
Definition _regex.h:19
@ ICASE
Definition Regex.h:35
@ NEWLINE
Definition Regex.h:37
@ NOSUBS
Definition Regex.h:36

◆ MatchFlags

Enumerator
NOTBOL 
NOTEOL 

Definition at line 40 of file Regex.h.

40 {
43 };
@ regex_not_bol
Definition _regex.h:39
@ regex_not_eol
Definition _regex.h:40
@ NOTBOL
Definition Regex.h:41
@ NOTEOL
Definition Regex.h:42

Constructor & Destructor Documentation

◆ Regex() [1/3]

Regex::Regex ( )

Definition at line 85 of file Regex.cpp.

86{
87 __handle = NULL;
88}
#define NULL
Definition Config.h:340

◆ ~Regex()

Regex::~Regex ( )

Definition at line 77 of file Regex.cpp.

78{
79 if (__handle) {
80 __regex_destroy(__handle);
81// __handle = NULL;
82 }
83}
void __regex_destroy(regex_handle _handle)
Definition _regex.cpp:53

◆ Regex() [2/3]

Regex::Regex ( const wchar_t * _pattern,
size_t _n,
unsigned int _flags = 0 )

Definition at line 90 of file Regex.cpp.

93{
94 __handle = NULL;
95 compile(_pattern, _n, _flags);
96}
void compile(const wchar_t *_pattern, size_t _n, unsigned int _flags=0) __DCL_THROWS1(RegexException *)
Definition Regex.cpp:105

◆ Regex() [3/3]

Regex::Regex ( const String & _pattern,
unsigned int _flags = 0 )

Definition at line 98 of file Regex.cpp.

100{
101 __handle = NULL;
102 compile(_pattern.data(), _pattern.length(), _flags);
103}

Member Function Documentation

◆ compile() [1/2]

void Regex::compile ( const String & _pattern,
unsigned int _flags = 0 )
inline

Definition at line 134 of file Regex.h.

136{
137 compile(_pattern.data(), _pattern.length(), _flags);
138}

◆ compile() [2/2]

void Regex::compile ( const wchar_t * _pattern,
size_t _n,
unsigned int _flags = 0 )

Definition at line 105 of file Regex.cpp.

108{
109 if (!__handle) {
110 __handle = __regex_create();
111 }
112
113 try {
114 __regex_compile(__handle, _pattern, _n, _flags);
115 }
116// catch (boost::bad_expression& e)
117 catch (std::exception& e) {
118 throw(new RegexException(typeid(e).name(), e.what()));
119 }
120}
regex_handle __regex_create()
Definition _regex.cpp:43
void __regex_compile(regex_handle _handle, const wchar_t *_pattern, size_t _n, unsigned int _flags)
Definition _regex.cpp:61

◆ match() [1/4]

bool Regex::match ( const String & _string,
MatchResults & _results,
unsigned int _flags = 0 )
inline

Definition at line 158 of file Regex.h.

160{
161 return match(_string.data(), _string.data() + _string.length(), _results, _flags);
162}
bool match(const wchar_t *_begin, const wchar_t *_end, unsigned int _flags) __DCL_THROWS1(RegexException *)
Definition Regex.cpp:162

◆ match() [2/4]

bool Regex::match ( const String & _string,
unsigned int _flags = 0 )
inline

Definition at line 152 of file Regex.h.

154{
155 return match(_string.data(), _string.data() + _string.length(), _flags);
156}

◆ match() [3/4]

bool Regex::match ( const wchar_t * _begin,
const wchar_t * _end,
Regex::MatchResults & _results,
unsigned int _flags = 0 )

Definition at line 180 of file Regex.cpp.

183{
184 __DCL_ASSERT(__handle != NULL);
185
186 try {
187 match_result* results = NULL;
188 size_t n = __regex_match(__handle, _begin, _end, &results, _flags);
189 if (n) {
190 _results.attach(results, n);
191 return true;
192 }
193 }
194// catch (std::runtime_error& e)
195 catch (std::exception& e) {
196 throw(new RegexException(typeid(e).name(), e.what()));
197 }
198
199 return false;
200}
size_t __regex_match(regex_handle _handle, const wchar_t *_begin, const wchar_t *_end, match_result **_results, unsigned int _flags)
Definition _regex.cpp:87
#define __DCL_ASSERT(expr)
Definition Object.h:371
void CharsetConvertException *size_t n
Definition SQLField.cpp:253

◆ match() [4/4]

bool Regex::match ( const wchar_t * _begin,
const wchar_t * _end,
unsigned int _flags )

Definition at line 162 of file Regex.cpp.

165{
166 __DCL_ASSERT(__handle != NULL);
167
168 bool r = false;
169 try {
170 r = __regex_match(__handle, _begin, _end, _flags);
171 }
172// catch (std::runtime_error& e)
173 catch (std::exception& e) {
174 throw(new RegexException(typeid(e).name(), e.what()));
175 }
176
177 return r;
178}
ByteString r

◆ replace()

String Regex::replace ( const String & _string,
const String & _replacement,
size_t _limit = (size_t)-1 )

Definition at line 202 of file Regex.cpp.

207{
208 const wchar_t* _begin = _string.data();
209 const wchar_t* _end = _string.data() + _string.length();
210 StringBuilder r;
211
212 MatchResults results;
213 while (_begin < _end && 0 < _limit && search(_begin, _end, results)) {
214 r.append(_begin, results[0].first);
215 r.append(_replacement);
216
217 _limit--;
218 _begin = results[0].second;
219 }
220
221 if (_begin < _end) {
222 r.append(_begin, _end);
223 }
224
225 return r;
226}
bool search(const wchar_t *_begin, const wchar_t *_end, unsigned int _flags=0) __DCL_THROWS1(RegexException *)
Definition Regex.cpp:122

◆ search() [1/4]

bool Regex::search ( const String & _string,
MatchResults & _results,
unsigned int _flags = 0 )
inline

Definition at line 146 of file Regex.h.

148{
149 return search(_string.data(), _string.data() + _string.length(), _results, _flags);
150}

◆ search() [2/4]

bool Regex::search ( const String & _string,
unsigned int _flags = 0 )
inline

Definition at line 140 of file Regex.h.

142{
143 return search(_string.data(), _string.data() + _string.length(), _flags);
144}

◆ search() [3/4]

bool Regex::search ( const wchar_t * _begin,
const wchar_t * _end,
Regex::MatchResults & _results,
unsigned int _flags = 0 )

Definition at line 140 of file Regex.cpp.

143{
144 __DCL_ASSERT(__handle != NULL);
145
146 try {
147 match_result* results = NULL;
148 size_t n = __regex_search(__handle, _begin, _end, &results, _flags);
149 if (n) {
150 _results.attach(results, n);
151 return true;
152 }
153 }
154// catch (std::runtime_error& e)
155 catch (std::exception& e) {
156 throw(new RegexException(typeid(e).name(), e.what()));
157 }
158
159 return false;
160}
bool __regex_search(regex_handle _handle, const wchar_t *_begin, const wchar_t *_end, match_result **_results, unsigned int _flags)
Definition _regex.cpp:137

◆ search() [4/4]

bool Regex::search ( const wchar_t * _begin,
const wchar_t * _end,
unsigned int _flags = 0 )

Definition at line 122 of file Regex.cpp.

125{
126 __DCL_ASSERT(__handle != NULL);
127
128 bool r = false;
129 try {
130 r = __regex_search(__handle, _begin, _end, _flags);
131 }
132// catch (std::runtime_error& e)
133 catch (std::exception& e) {
134 throw(new RegexException(typeid(e).name(), e.what()));
135 }
136
137 return r;
138}

◆ split() [1/2]

size_t Regex::split ( const String & _string,
StringArray & _results,
size_t _limit = (size_t)-1 )
inline

Definition at line 164 of file Regex.h.

169{
170 return split(_string.data(), _string.data() + _string.length(), _results, _limit);
171}
size_t split(const wchar_t *_begin, const wchar_t *_end, StringArray &_results, size_t _limit=(size_t) -1) __DCL_THROWS1(RegexException *)
Definition Regex.cpp:228

◆ split() [2/2]

size_t Regex::split ( const wchar_t * _begin,
const wchar_t * _end,
StringArray & _results,
size_t _limit = (size_t)-1 )

Definition at line 228 of file Regex.cpp.

233{
234 __DCL_ASSERT(_begin != NULL && _end != NULL);
235 __DCL_ASSERT(_begin <= _end);
236
237 MatchResults results;
238 while(_begin < _end && _limit > 0 && search(_begin, _end, results)) {
239 _results.add(String(_begin, results[0].first - _begin));
240
241 _limit--;
242 _begin = results[0].second;
243 }
244
245 if (_begin < _end) {
246 _results.add(String(_end, _end - _begin));
247 }
248
249 return _results.size();
250}
size_t size() const
Definition Regex.h:57

◆ test() [1/2]

bool Regex::test ( const char * _regex,
const char * _string,
bool _icase = false )
static

Definition at line 267 of file Regex.cpp.

272{
273 __DCL_ASSERT_PARAM(_regex != NULL);
274 __DCL_ASSERT_PARAM(_string != NULL);
275 return __regex_search(
276 _regex, _regex + ByteString::length(_regex),
277 _string, _string + ByteString::length(_string),
278 _icase
279 ) != (size_t)-1;;
280}
#define __DCL_ASSERT_PARAM(expr)
Definition Object.h:384

◆ test() [2/2]

bool Regex::test ( const wchar_t * _regex,
const wchar_t * _string,
bool _icase = false )
static

Definition at line 252 of file Regex.cpp.

257{
258 __DCL_ASSERT_PARAM(_regex != NULL);
259 __DCL_ASSERT_PARAM(_string != NULL);
260 return __regex_search(
261 _regex, _regex + String::length(_regex),
262 _string, _string + String::length(_string),
263 _icase
264 ) != (size_t)-1;
265}

The documentation for this class was generated from the following files: