DCL 3.7.4
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 83 of file Regex.cpp.

84{
85 __handle = NULL;
86}
#define NULL
Definition Config.h:312

◆ ~Regex()

Regex::~Regex ( )

Definition at line 75 of file Regex.cpp.

76{
77 if (__handle) {
78 __regex_destroy(__handle);
79// __handle = NULL;
80 }
81}
void __regex_destroy(regex_handle _handle)
Definition _regex.cpp:54

◆ Regex() [2/3]

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

Definition at line 88 of file Regex.cpp.

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

◆ Regex() [3/3]

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

Definition at line 96 of file Regex.cpp.

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

Member Function Documentation

◆ compile() [1/2]

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

Definition at line 138 of file Regex.h.

142{
143 compile(_pattern.data(), _pattern.length(), _flags);
144}

◆ compile() [2/2]

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

Definition at line 103 of file Regex.cpp.

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

◆ match() [1/4]

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

Definition at line 179 of file Regex.h.

183{
184 return match(
185 _string.data(), _string.data() + _string.length(),
186 _results, _flags
187 );
188}
bool match(const wchar_t *_begin, const wchar_t *_end, unsigned int _flags) __DCL_THROWS1(RegexException *)
Definition Regex.cpp:160

◆ match() [2/4]

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

Definition at line 168 of file Regex.h.

172{
173 return match(
174 _string.data(), _string.data() + _string.length(),
175 _flags
176 );
177}

◆ match() [3/4]

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

Definition at line 178 of file Regex.cpp.

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

◆ match() [4/4]

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

Definition at line 160 of file Regex.cpp.

163{
164 __DCL_ASSERT(__handle != NULL);
165
166 bool r = false;
167 try {
168 r = __regex_match(__handle, _begin, _end, _flags);
169 }
170// catch (std::runtime_error& e)
171 catch (std::exception& e) {
172 throw(new RegexException(typeid(e).name(), e.what()));
173 }
174
175 return r;
176}
IOException *size_t r
Definition MediaInfo.cpp:82

◆ replace()

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

Definition at line 200 of file Regex.cpp.

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

◆ search() [1/4]

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

Definition at line 157 of file Regex.h.

161{
162 return search(
163 _string.data(), _string.data() + _string.length(),
164 _results, _flags
165 );
166}

◆ search() [2/4]

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

Definition at line 146 of file Regex.h.

150{
151 return search(
152 _string.data(), _string.data() + _string.length(),
153 _flags
154 );
155}

◆ search() [3/4]

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

Definition at line 138 of file Regex.cpp.

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

◆ search() [4/4]

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

Definition at line 120 of file Regex.cpp.

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

◆ split() [1/2]

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

Definition at line 190 of file Regex.h.

195{
196 return split(
197 _string.data(), _string.data() + _string.length(),
198 _results, _limit
199 );
200}
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:226

◆ 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 226 of file Regex.cpp.

231{
232 __DCL_ASSERT(_begin != NULL && _end != NULL);
233 __DCL_ASSERT(_begin <= _end);
234
235 MatchResults results;
236 while(_begin < _end && _limit > 0 && search(_begin, _end, results)) {
237 _results.add(String(_begin, results[0].first - _begin));
238
239 _limit--;
240 _begin = results[0].second;
241 }
242
243 if (_begin < _end) {
244 _results.add(String(_end, _end - _begin));
245 }
246
247 return _results.size();
248}
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 265 of file Regex.cpp.

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

◆ test() [2/2]

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

Definition at line 250 of file Regex.cpp.

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

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