1 |
< |
// Smersh |
1 |
> |
// Zoe AIM Away Message RSS Feed Generator |
2 |
|
// |
3 |
|
// Douglas Thrift |
4 |
|
// |
6 |
|
|
7 |
|
#include "Matcher.hpp" |
8 |
|
|
9 |
< |
Matcher::Matcher(const std::string& expression) |
10 |
< |
{ |
11 |
< |
this->expression = NULL; |
12 |
< |
|
13 |
< |
(*this)(expression); |
14 |
< |
} |
15 |
< |
|
16 |
< |
Matcher::~Matcher() |
17 |
< |
{ |
18 |
< |
if (expression != NULL) |
19 |
< |
{ |
20 |
< |
pcre_free(expression); |
21 |
< |
} |
22 |
< |
} |
23 |
< |
|
24 |
< |
bool Matcher::match(const std::string& stuff) |
9 |
> |
bool Matcher::match(const ext::String& stuff) |
10 |
|
{ |
11 |
|
substrings.clear(); |
12 |
|
|
16 |
|
|
17 |
|
pcre_fullinfo(expression, NULL, PCRE_INFO_CAPTURECOUNT, &length); |
18 |
|
|
19 |
< |
int* substrings = new int[(++length *= 3)]; |
20 |
< |
int count = pcre_exec(expression, NULL, stuff.c_str(), stuff.length(), |
36 |
< |
0, 0, substrings, length); |
19 |
> |
int* substrings(new int[(++length *= 3)]); |
20 |
> |
int count(pcre_exec(expression, NULL, stuff.NullTerminate(), stuff.GetSize(), 0, 0, substrings, length)); |
21 |
|
|
22 |
|
if (count > 0) |
23 |
|
{ |
24 |
< |
char* substring = new char[stuff.length() + 1]; |
24 |
> |
char* substring(new char[stuff.length() + 1]); |
25 |
|
|
26 |
< |
for (int index = 0; index < count; index++) |
26 |
> |
for (int index(0); index < count; ++index) |
27 |
|
{ |
28 |
< |
pcre_copy_substring(stuff.c_str(), substrings, count, index, |
45 |
< |
substring, stuff.length() + 1); |
28 |
> |
pcre_copy_substring(stuff.NullTerminate(), substrings, count, index, substring, stuff.GetSize() + 1); |
29 |
|
|
30 |
|
this->substrings.push_back(substring); |
31 |
|
} |
41 |
|
return false; |
42 |
|
} |
43 |
|
|
44 |
< |
Matcher& Matcher::operator()(const std::string& expression) |
44 |
> |
Matcher& Matcher::operator()(const ext::String& expression) |
45 |
|
{ |
46 |
|
substrings.clear(); |
47 |
|
|
48 |
< |
if (this->expression != NULL) |
66 |
< |
{ |
67 |
< |
pcre_free(this->expression); |
68 |
< |
} |
48 |
> |
if (this->expression != NULL) pcre_free(this->expression); |
49 |
|
|
50 |
|
const char* error; |
51 |
|
int offset; |
52 |
|
|
53 |
< |
this->expression = pcre_compile(expression.c_str(), 0, &error, |
74 |
< |
&offset, NULL); |
53 |
> |
this->expression = pcre_compile(expression.NullTerminate(), 0, &error, &offset, NULL); |
54 |
|
|
55 |
|
return *this; |
56 |
|
} |