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