DCL 4.0
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(const wchar_t* _begin, const wchar_t* _end, MatchResults& _results, unsigned int _flags = 0)
77
78 bool match(const wchar_t* _begin, const wchar_t* _end, unsigned int _flags)
80
81 bool match(const wchar_t* _begin, const wchar_t* _end, MatchResults& _results, unsigned int _flags = 0)
83
84
85 Regex(const String& _pattern, unsigned int _flags = 0)
87
88 void compile(const String& _pattern, unsigned int _flags = 0)
90
91 bool search(const String& _string, unsigned int _flags = 0)
93
94 bool search(const String& _string, MatchResults& _results, unsigned int _flags = 0)
96
97 bool match(const String& _string, unsigned int _flags = 0)
99
100 bool match(const String& _string, MatchResults& _results, unsigned int _flags = 0)
102
103 String replace(
104 const String& _string,
105 const String& _replacement,
106 size_t _limit = (size_t)-1
108
109 size_t split(
110 const wchar_t* _begin, const wchar_t* _end,
111 StringArray& _results,
112 size_t _limit = (size_t)-1 // unlimited
114
115 size_t split(
116 const String& _string,
117 StringArray& _results,
118 size_t _limit = (size_t)-1 // unlimited
120
121 static bool test(
122 const wchar_t* _regex,
123 const wchar_t* _string,
124 bool _icase = false
126
127 static bool test(
128 const char* _regex,
129 const char* _string,
130 bool _icase = false
132};
133
134inline void Regex::compile(const String& _pattern, unsigned int _flags) // = 0)
136{
137 compile(_pattern.data(), _pattern.length(), _flags);
138}
139
140inline bool Regex::search(const String& _string, unsigned int _flags) // = 0)
142{
143 return search(_string.data(), _string.data() + _string.length(), _flags);
144}
145
146inline bool Regex::search(const String& _string, MatchResults& _results, unsigned int _flags) // = 0)
148{
149 return search(_string.data(), _string.data() + _string.length(), _results, _flags);
150}
151
152inline bool Regex::match(const String& _string, unsigned int _flags) // = 0)
154{
155 return match(_string.data(), _string.data() + _string.length(), _flags);
156}
157
158inline bool Regex::match(const String& _string, MatchResults& _results, unsigned int _flags) // = 0)
160{
161 return match(_string.data(), _string.data() + _string.length(), _results, _flags);
162}
163
164inline size_t Regex::split(
165 const String& _string,
166 StringArray& _results,
167 size_t _limit // = (size_t)-1 // unlimited
169{
170 return split(_string.data(), _string.data() + _string.length(), _results, _limit);
171}
172
173__DCL_END_NAMESPACE
174
175#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:100
#define __DCL_THROWS1(e)
Definition Config.h:167
#define DECLARE_CLASSINFO(class_name)
Definition Object.h:210
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:228
bool search(const wchar_t *_begin, const wchar_t *_end, unsigned int _flags=0) __DCL_THROWS1(RegexException *)
Definition Regex.cpp:122
MatchFlags
Definition Regex.h:40
@ NOTBOL
Definition Regex.h:41
@ NOTEOL
Definition Regex.h:42
Regex()
Definition Regex.cpp:85
bool match(const wchar_t *_begin, const wchar_t *_end, unsigned int _flags) __DCL_THROWS1(RegexException *)
Definition Regex.cpp:162
void compile(const wchar_t *_pattern, size_t _n, unsigned int _flags=0) __DCL_THROWS1(RegexException *)
Definition Regex.cpp:105