DCL 4.0
Loading...
Searching...
No Matches
_regex.h File Reference

Go to the source code of this file.

Classes

struct  match_result

Typedefs

typedef void * regex_handle

Enumerations

enum  regex_compile_flags { regex_icase = 0x0001 , regex_nosubs = 0x0002 , regex_newline = 0x0004 }
enum  regex_match_flags { regex_not_bol = 0x0001 , regex_not_eol = 0x0002 }

Functions

regex_handle __regex_create ()
void __regex_destroy (regex_handle _handle)
void __regex_compile (regex_handle _handle, const wchar_t *_pattern, size_t _n, unsigned int _flags)
void __matches_free (match_result *_results)
size_t __regex_match (regex_handle _handle, const wchar_t *_begin, const wchar_t *_end, match_result **_results, unsigned int _flags)
bool __regex_match (regex_handle _handle, const wchar_t *_begin, const wchar_t *_end, unsigned int _flags)
bool __regex_search (regex_handle _handle, const wchar_t *_begin, const wchar_t *_end, match_result **_results, unsigned int _flags)
bool __regex_search (regex_handle _handle, const wchar_t *_begin, const wchar_t *_end, unsigned int _flags)
bool __regex_matches (const wchar_t *_regex, const wchar_t *_regexend, const wchar_t *_begin, const wchar_t *_end, bool _icase) __DCL_THROWS1(RegexException *)
bool __regex_matches (const char *_regex, const char *_regexend, const char *_begin, const char *_end, bool _icase) __DCL_THROWS1(RegexException *)
size_t __regex_search (const wchar_t *_regex, const wchar_t *_regexend, const wchar_t *_begin, const wchar_t *_end, bool _icase) __DCL_THROWS1(RegexException *)
size_t __regex_search (const char *_regex, const char *_regexend, const char *_begin, const char *_end, bool _icase) __DCL_THROWS1(RegexException *)
String __regex_substring (const wchar_t *_regex, const wchar_t *_regexend, const wchar_t *_begin, const wchar_t *_end, bool _icase) __DCL_THROWS1(RegexException *)
ByteString __regex_substring (const char *_regex, const char *_regexend, const char *_begin, const char *_end, bool _icase) __DCL_THROWS1(RegexException *)
String __regex_replace (const wchar_t *_regex, const wchar_t *_regexend, const wchar_t *_begin, const wchar_t *_end, const wchar_t *_replacement, const wchar_t *_replacementend, bool _icase, size_t _limit=(size_t) -1) __DCL_THROWS1(RegexException *)
ByteString __regex_replace (const char *_regex, const char *_regexend, const char *_begin, const char *_end, const char *_replacement, const char *_replacementend, bool _icase, size_t _limit=(size_t) -1) __DCL_THROWS1(RegexException *)
StringArray & __regex_split (const wchar_t *_regex, const wchar_t *_regexend, const wchar_t *_begin, const wchar_t *_end, bool _icase, StringArray &_results, size_t _limit=(size_t) -1) __DCL_THROWS1(RegexException *)
ByteStringArray & __regex_split (const char *_regex, const char *_regexend, const char *_begin, const char *_end, bool _icase, ByteStringArray &_results, size_t _limit=(size_t) -1) __DCL_THROWS1(RegexException *)

Typedef Documentation

◆ regex_handle

typedef void* regex_handle

Definition at line 12 of file _regex.h.

Enumeration Type Documentation

◆ regex_compile_flags

Enumerator
regex_icase 
regex_nosubs 
regex_newline 

Definition at line 17 of file _regex.h.

17 {
18 regex_icase = 0x0001,
19 regex_nosubs = 0x0002,
20 regex_newline = 0x0004
21};
@ regex_icase
Definition _regex.h:18
@ regex_newline
Definition _regex.h:20
@ regex_nosubs
Definition _regex.h:19

◆ regex_match_flags

Enumerator
regex_not_bol 
regex_not_eol 

Definition at line 38 of file _regex.h.

38 {
39 regex_not_bol = 0x0001,
40 regex_not_eol = 0x0002
41};
@ regex_not_bol
Definition _regex.h:39
@ regex_not_eol
Definition _regex.h:40

Function Documentation

◆ __matches_free()

void __matches_free ( match_result * _results)

Definition at line 81 of file _regex.cpp.

82{
83 free(_results);
84// delete[] _results;
85}

◆ __regex_compile()

void __regex_compile ( regex_handle _handle,
const wchar_t * _pattern,
size_t _n,
unsigned int _flags )

Definition at line 61 of file _regex.cpp.

66{
67 wregex::flag_type flags = wregex::extended;// wregex::normal;
68 if (_flags & regex_icase)
69 flags |= wregex::icase;
70 if (_flags & regex_nosubs)
71 flags |= wregex::nosubs;
72#if 0
73 if (_flags & regex_newline)
74 flags |= wregex::newline_alt;
75#endif
77 ((wregex*)_handle)->assign(_pattern, _pattern + _n, flags);
79}
#define __DCL_DEBUG_ALLOC_LEAVE
Definition Object.h:647
#define __DCL_DEBUG_ALLOC_ENTER
Definition Object.h:646

◆ __regex_create()

regex_handle __regex_create ( )

Definition at line 43 of file _regex.cpp.

44{
45 //wregex* p = (wregex*)malloc(sizeof(wregex));
46 //return new(p) wregex;
48 regex_handle r = (regex_handle)new wregex();
50 return r;
51}
void * regex_handle
Definition _regex.h:12
ByteString r

◆ __regex_destroy()

void __regex_destroy ( regex_handle _handle)

Definition at line 53 of file _regex.cpp.

54{
55 //wregex* p = (wregex*)_handle;
56 //p->~wregex();
57 //free(p);
58 delete (wregex*)_handle;
59}

◆ __regex_match() [1/2]

size_t __regex_match ( regex_handle _handle,
const wchar_t * _begin,
const wchar_t * _end,
match_result ** _results,
unsigned int _flags )

Definition at line 87 of file _regex.cpp.

92{
93 regex_constants::match_flag_type flags = regex_constants::match_default;
94 if (_flags & regex_not_bol)
95 flags |= regex_constants::match_not_bol;
96 if (_flags & regex_not_eol)
97 flags |= regex_constants::match_not_eol;
98
99 wcmatch m;
101 bool b = regex_match(_begin, _end, m, *((const wregex*)_handle), flags);
103 if (b)
104 {
105 match_result* match = (match_result*)malloc(sizeof(match_result) * m.size());
106 for(size_t i = 0; i < m.size(); i++)
107 {
108 match[i].first = m[i].first;
109 match[i].second = m[i].second;
110 match[i].matched = m[i].matched;
111 }
112 *_results = match;
113 return m.size();
114 }
115 *_results = NULL;
116 return 0;
117}
#define NULL
Definition Config.h:340
const wchar_t * first
Definition _regex.h:33
const wchar_t * second
Definition _regex.h:34
bool matched
Definition _regex.h:35

◆ __regex_match() [2/2]

bool __regex_match ( regex_handle _handle,
const wchar_t * _begin,
const wchar_t * _end,
unsigned int _flags )

Definition at line 119 of file _regex.cpp.

124{
125 regex_constants::match_flag_type flags = regex_constants::match_default;
126 if (_flags & regex_not_bol)
127 flags |= regex_constants::match_not_bol;
128 if (_flags & regex_not_eol)
129 flags |= regex_constants::match_not_eol;
130
132 bool r = regex_match(_begin, _end, *(const wregex*)_handle, flags);
134 return r;
135}

◆ __regex_matches() [1/2]

bool __regex_matches ( const char * _regex,
const char * _regexend,
const char * _begin,
const char * _end,
bool _icase )

Definition at line 212 of file _regex.cpp.

217{
218 regex::flag_type flags = regex::ECMAScript;
219 if (_icase) {
220 flags |= regex::icase;
221 }
222
223 try {
225 regex re(_regex, _regexend, flags);
227 bool r = regex_match(_begin, _end, re);
229 return r;
230 }
231 // catch (std::runtime_error& e)
232 catch (std::exception& e) {
233 throw(new RegexException(typeid(e).name(), e.what()));
234 }
235}

◆ __regex_matches() [2/2]

bool __regex_matches ( const wchar_t * _regex,
const wchar_t * _regexend,
const wchar_t * _begin,
const wchar_t * _end,
bool _icase )

Definition at line 187 of file _regex.cpp.

192{
193 regex::flag_type flags = regex::ECMAScript;
194 if (_icase) {
195 flags |= regex::icase;
196 }
197
198 try {
200 wregex re(_regex, _regexend, flags);
202 bool r = regex_match(_begin, _end, re);
204 return r;
205 }
206 // catch (std::runtime_error& e)
207 catch (std::exception& e) {
208 throw(new RegexException(typeid(e).name(), e.what()));
209 }
210}

◆ __regex_replace() [1/2]

ByteString __regex_replace ( const char * _regex,
const char * _regexend,
const char * _begin,
const char * _end,
const char * _replacement,
const char * _replacementend,
bool _icase,
size_t _limit = (size_t) -1 )

Definition at line 408 of file _regex.cpp.

415{
416 regex::flag_type flags = regex::ECMAScript | regex::nosubs;
417 if (_icase) {
418 flags |= regex::icase;
419 }
420
421 try {
422 ByteStringBuilder r;
424 regex re(_regex, _regexend, flags);
426 cmatch m;
428 while (_begin < _end && _limit && regex_search(_begin, _end, m, re)) {
429 __DCL_ASSERT(m.size() > 0);
430 r.append(_begin, m[0].first)
431 .append(_replacement, _replacementend);
432
433 _limit--;
434 _begin = m[0].second;
435 }
436
437 if (_begin < _end) {
438 r.append(_begin, _end);
439 }
440
441 return r;
442 }
443 // catch (std::runtime_error& e)
444 catch (std::exception& e) {
445 throw(new RegexException(typeid(e).name(), e.what()));
446 }
447}
#define __DCL_ASSERT(expr)
Definition Object.h:371

◆ __regex_replace() [2/2]

String __regex_replace ( const wchar_t * _regex,
const wchar_t * _regexend,
const wchar_t * _begin,
const wchar_t * _end,
const wchar_t * _replacement,
const wchar_t * _replacementend,
bool _icase,
size_t _limit = (size_t) -1 )

Definition at line 367 of file _regex.cpp.

374{
375 regex::flag_type flags = regex::ECMAScript | regex::nosubs;
376 if (_icase) {
377 flags |= regex::icase;
378 }
379
380 try {
381 StringBuilder r;
383 wregex re(_regex, _regexend, flags);
385 wcmatch m;
387 while (_begin < _end && _limit && regex_search(_begin, _end, m, re)) {
388 __DCL_ASSERT(m.size() > 0);
389 r.append(_begin, m[0].first)
390 .append(_replacement, _replacementend);
391
392 _limit--;
393 _begin = m[0].second;
394 }
395
396 if (_begin < _end) {
397 r.append(_begin, _end);
398 }
399
400 return r;
401 }
402 // catch (std::runtime_error& e)
403 catch (std::exception& e) {
404 throw(new RegexException(typeid(e).name(), e.what()));
405 }
406}

◆ __regex_search() [1/4]

size_t __regex_search ( const char * _regex,
const char * _regexend,
const char * _begin,
const char * _end,
bool _icase )

Definition at line 269 of file _regex.cpp.

274{
275 // GNUC BUG!!
276 // regex re(_pattern, regex::extended | (_icase ? regex::icase : 0));
277 regex::flag_type flags = regex::ECMAScript | regex::nosubs;
278 if (_icase) {
279 flags |= regex::icase;
280 }
281
282 size_t r = (size_t)-1;
283 try {
285 regex re(_regex, _regexend, flags);
287 cmatch m;
290 if (regex_search(_begin, _end, m, re)) {
291 r = m[0].first - _begin;
292 }
294 }
295 // catch (std::runtime_error& e)
296 catch (std::exception& e) {
297 throw(new RegexException(typeid(e).name(), e.what()));
298 }
299 return r;
300}

◆ __regex_search() [2/4]

size_t __regex_search ( const wchar_t * _regex,
const wchar_t * _regexend,
const wchar_t * _begin,
const wchar_t * _end,
bool _icase )

Definition at line 237 of file _regex.cpp.

242{
243 // GNUC BUG!!
244 // regex re(_pattern, regex::extended | (_icase ? regex::icase : 0));
245 regex::flag_type flags = regex::ECMAScript | regex::nosubs;
246 if (_icase) {
247 flags |= regex::icase;
248 }
249
250 size_t r = (size_t)-1;
251 try {
253 wregex re(_regex, _regexend, flags);
255 wcmatch m;
257 if (regex_search(_begin, _end, m, re)) {
258 r = m[0].first - _begin;
259 }
261 }
262 // catch (std::runtime_error& e)
263 catch (std::exception& e) {
264 throw(new RegexException(typeid(e).name(), e.what()));
265 }
266 return r;
267}

◆ __regex_search() [3/4]

bool __regex_search ( regex_handle _handle,
const wchar_t * _begin,
const wchar_t * _end,
match_result ** _results,
unsigned int _flags )

Definition at line 137 of file _regex.cpp.

142{
143 regex_constants::match_flag_type flags = regex_constants::match_default;
144 if (_flags & regex_not_bol)
145 flags |= regex_constants::match_not_bol;
146 if (_flags & regex_not_eol)
147 flags |= regex_constants::match_not_eol;
148
149 wcmatch m;
151 bool r = regex_search(_begin, _end, m, *((const wregex*)_handle), flags);
153 if (r)
154 {
155 match_result* match = (match_result*)malloc(sizeof(match_result) * m.size());
156 for(size_t i = 0; i < m.size(); i++)
157 {
158 match[i].first = m[i].first;
159 match[i].second = m[i].second;
160 match[i].matched = m[i].matched;
161 }
162 *_results = match;
163 return m.size();
164 }
165 *_results = NULL;
166 return r;
167}

◆ __regex_search() [4/4]

bool __regex_search ( regex_handle _handle,
const wchar_t * _begin,
const wchar_t * _end,
unsigned int _flags )

Definition at line 169 of file _regex.cpp.

174{
175 regex_constants::match_flag_type flags = regex_constants::match_default;
176 if (_flags & regex_not_bol)
177 flags |= regex_constants::match_not_bol;
178 if (_flags & regex_not_eol)
179 flags |= regex_constants::match_not_eol;
180
182 bool r = regex_search(_begin, _end, *(const wregex*)_handle, flags);
184 return r;
185}

◆ __regex_split() [1/2]

ByteStringArray & __regex_split ( const char * _regex,
const char * _regexend,
const char * _begin,
const char * _end,
bool _icase,
ByteStringArray & _results,
size_t _limit = (size_t) -1 )

Definition at line 488 of file _regex.cpp.

495{
496 regex::flag_type flags = regex::ECMAScript | regex::nosubs;
497 if (_icase) {
498 flags |= regex::icase;
499 }
500
501 try {
503 regex re(_regex, _regexend, flags);
505 cmatch m;
507 while (_begin < _end && _limit && regex_search(_begin, _end, m, re)) {
508 __DCL_ASSERT(m.size() > 0);
509 _results.add(ByteString(_begin, m[0].first));
510
511 _limit--;
512 _begin = m[0].second;
513 }
514
515 if (_begin < _end) {
516 _results.add(ByteString(_begin, _end));
517 }
518
519 return _results;
520 }
521 // catch (std::runtime_error& e)
522 catch (std::exception& e) {
523 throw(new RegexException(typeid(e).name(), e.what()));
524 }
525}

◆ __regex_split() [2/2]

StringArray & __regex_split ( const wchar_t * _regex,
const wchar_t * _regexend,
const wchar_t * _begin,
const wchar_t * _end,
bool _icase,
StringArray & _results,
size_t _limit = (size_t) -1 )

Definition at line 449 of file _regex.cpp.

456{
457 regex::flag_type flags = regex::ECMAScript | regex::nosubs;
458 if (_icase) {
459 flags |= regex::icase;
460 }
461
462 try {
464 wregex re(_regex, _regexend, flags);
466 wcmatch m;
468 while (_begin < _end && _limit && regex_search(_begin, _end, m, re)) {
469 __DCL_ASSERT(m.size() > 0);
470 _results.add(String(_begin, m[0].first));
471
472 _limit--;
473 _begin = m[0].second;
474 }
475
476 if (_begin < _end) {
477 _results.add(String(_begin, _end));
478 }
479
480 return _results;
481 }
482 // catch (std::runtime_error& e)
483 catch (std::exception& e) {
484 throw(new RegexException(typeid(e).name(), e.what()));
485 }
486}

◆ __regex_substring() [1/2]

ByteString __regex_substring ( const char * _regex,
const char * _regexend,
const char * _begin,
const char * _end,
bool _icase )

Definition at line 334 of file _regex.cpp.

339{
340 // GNUC BUG!!
341 // regex re(_pattern, regex::extended | (_icase ? regex::icase : 0));
342 regex::flag_type flags = regex::ECMAScript | regex::nosubs;
343 if (_icase) {
344 flags |= regex::icase;
345 }
346
347 ByteString r;
348 try {
350 regex re(_regex, _regexend, flags);
352 cmatch m;
355 if (regex_search(_begin, _end, m, re)) {
356 r.assign(m[0].first, m[0].second);
357 }
359 }
360 // catch (std::runtime_error& e)
361 catch (std::exception& e) {
362 throw(new RegexException(typeid(e).name(), e.what()));
363 }
364 return r;
365}

◆ __regex_substring() [2/2]

String __regex_substring ( const wchar_t * _regex,
const wchar_t * _regexend,
const wchar_t * _begin,
const wchar_t * _end,
bool _icase )

Definition at line 302 of file _regex.cpp.

307{
308 // GNUC BUG!!
309 // regex re(_pattern, regex::extended | (_icase ? regex::icase : 0));
310 regex::flag_type flags = regex::ECMAScript | regex::nosubs;
311 if (_icase) {
312 flags |= regex::icase;
313 }
314
315 String r;
316 try {
318 wregex re(_regex, _regexend, flags);
320 wcmatch m;
322 if (regex_search(_begin, _end, m, re)) {
323 r.assign(m[0].first, m[0].second);
324 }
326 }
327 // catch (std::runtime_error& e)
328 catch (std::exception& e) {
329 throw(new RegexException(typeid(e).name(), e.what()));
330 }
331 return r;
332}