DCL 3.7.4
Loading...
Searching...
No Matches
Regex.h
Go to the documentation of this file.
1#ifndef __DCL_REGEX_H__
2#define __DCL_REGEX_H__ 20041119
3
4#ifndef __DCL_CONFIG_H__
5#include <dcl/Config.h>
6#endif
7#ifndef __DCL_EXCEPTION_H__
8#include <dcl/Exception.h>
9#endif
10#ifndef __DCL_STRING_H__
11#include <dcl/String.h>
12#endif
13
14#include <dcl/_regex.h>
15
16__DCL_BEGIN_NAMESPACE
17
18class StringArray;
19
21{
23public:
24 RegexException(const char* _name, const char* _what);
25 virtual String toString() const;
26
27protected:
28 String __message;
29};
30
32{
33public:
39
44
46 {
47 private:
48 match_result* __results;
49 size_t __size;
50 void attach(match_result* _results, size_t _size);
51 friend class Regex;
52 public:
55 const match_result& operator [] (size_t _index) const
57 size_t size() const { return __size; }
58 };
59
60private:
61 void* __handle;
62public:
63 Regex();
64 ~Regex();
65
66 Regex(const wchar_t* _pattern, size_t _n, unsigned int _flags = 0)
68
69 void compile(const wchar_t* _pattern, size_t _n, unsigned int _flags = 0)
71
72 bool search(const wchar_t* _begin, const wchar_t* _end, unsigned int _flags = 0)
74
75 bool search(
76 const wchar_t* _begin, const wchar_t* _end,
77 MatchResults& _results, unsigned int _flags = 0
79
80 bool match(
81 const wchar_t* _begin, const wchar_t* _end, unsigned int _flags
83
84 bool match(
85 const wchar_t* _begin, const wchar_t* _end,
86 MatchResults& _results, unsigned int _flags = 0
88
89 Regex(const String& _pattern, unsigned int _flags = 0)
91
92 void compile(const String& _pattern, unsigned int _flags = 0)
94
95 bool search(const String& _string, unsigned int _flags = 0)
97
98 bool search(const String& _string, MatchResults& _results, unsigned int _flags = 0)
100
101 bool match(const String& _string, unsigned int _flags = 0)
103
104 bool match(const String& _string, MatchResults& _results, unsigned int _flags = 0)
106
107 String replace(
108 const String& _string,
109 const String& _replacement,
110 size_t _limit = (size_t)-1
112
113 size_t split(
114 const wchar_t* _begin, const wchar_t* _end,
115 StringArray& _results,
116 size_t _limit = (size_t)-1 // unlimited
118
119 size_t split(
120 const String& _string,
121 StringArray& _results,
122 size_t _limit = (size_t)-1 // unlimited
124
125 static bool test(
126 const wchar_t* _regex,
127 const wchar_t* _string,
128 bool _icase = false
130
131 static bool test(
132 const char* _regex,
133 const char* _string,
134 bool _icase = false
136};
137
138inline void Regex::compile(
139 const String& _pattern,
140 unsigned int _flags // = 0
142{
143 compile(_pattern.data(), _pattern.length(), _flags);
144}
145
146inline bool Regex::search(
147 const String& _string,
148 unsigned int _flags // = 0
150{
151 return search(
152 _string.data(), _string.data() + _string.length(),
153 _flags
154 );
155}
156
157inline bool Regex::search(
158 const String& _string, MatchResults& _results,
159 unsigned int _flags // = 0
161{
162 return search(
163 _string.data(), _string.data() + _string.length(),
164 _results, _flags
165 );
166}
167
168inline bool Regex::match(
169 const String& _string,
170 unsigned int _flags // = 0
172{
173 return match(
174 _string.data(), _string.data() + _string.length(),
175 _flags
176 );
177}
178
179inline bool Regex::match(
180 const String& _string, MatchResults& _results,
181 unsigned int _flags // = 0
183{
184 return match(
185 _string.data(), _string.data() + _string.length(),
186 _results, _flags
187 );
188}
189
190inline size_t Regex::split(
191 const String& _string,
192 StringArray& _results,
193 size_t _limit // = (size_t)-1 // unlimited
195{
196 return split(
197 _string.data(), _string.data() + _string.length(),
198 _results, _limit
199 );
200}
201
202__DCL_END_NAMESPACE
203
204#endif // __DCL_REGEX_H__
@ regex_not_bol
Definition _regex.h:39
@ regex_not_eol
Definition _regex.h:40
@ regex_icase
Definition _regex.h:18
@ regex_newline
Definition _regex.h:20
@ regex_nosubs
Definition _regex.h:19
#define DCLCAPI
Definition Config.h:95
#define __DCL_THROWS1(e)
Definition Config.h:152
#define DECLARE_CLASSINFO(class_name)
Definition Object.h:227
virtual String toString() const
Definition Exception.cpp:40
Exception(Exception *_cause=NULL)
friend class Regex
Definition Regex.h:51
size_t size() const
Definition Regex.h:57
String __message
Definition Regex.h:28
Definition Regex.h:32
CompileFlags
Definition Regex.h:34
@ ICASE
Definition Regex.h:35
@ NEWLINE
Definition Regex.h:37
@ NOSUBS
Definition Regex.h:36
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
bool search(const wchar_t *_begin, const wchar_t *_end, unsigned int _flags=0) __DCL_THROWS1(RegexException *)
Definition Regex.cpp:120
MatchFlags
Definition Regex.h:40
@ NOTBOL
Definition Regex.h:41
@ NOTEOL
Definition Regex.h:42
Regex()
Definition Regex.cpp:83
bool match(const wchar_t *_begin, const wchar_t *_end, unsigned int _flags) __DCL_THROWS1(RegexException *)
Definition Regex.cpp:160
void compile(const wchar_t *_pattern, size_t _n, unsigned int _flags=0) __DCL_THROWS1(RegexException *)
Definition Regex.cpp:103