ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/zoe/trunk/Matcher.cpp
Revision: 58
Committed: 2004-09-12T15:18:25-07:00 (20 years, 9 months ago) by douglas
File size: 1157 byte(s)
Log Message:
I can finally commit again!

File Contents

# User Rev Content
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 58 int count(pcre_exec(expression, NULL, stuff.NullTerminate(),
21     stuff.GetData().GetSize(), 0, 0, substrings, length));
22 douglas 5
23     if (count > 0)
24     {
25 douglas 58 char* substring(new char[stuff.GetData().GetSize() + 1]);
26 douglas 5
27 douglas 10 for (int index(0); index < count; ++index)
28 douglas 5 {
29 douglas 58 pcre_copy_substring(stuff.NullTerminate(), substrings, count,
30     index, substring, stuff.GetData().GetSize() + 1);
31 douglas 5
32     this->substrings.push_back(substring);
33     }
34    
35     delete [] substring;
36     delete [] substrings;
37     return true;
38     }
39    
40     delete [] substrings;
41     }
42    
43     return false;
44     }
45    
46 douglas 7 Matcher& Matcher::operator()(const ext::String& expression)
47 douglas 5 {
48     substrings.clear();
49    
50 douglas 34 if (this->expression != NULL) pcre_free(this->expression);
51 douglas 5
52     const char* error;
53     int offset;
54    
55 douglas 58 this->expression = pcre_compile(expression.NullTerminate(), 0, &error,
56     &offset, NULL);
57 douglas 5
58     return *this;
59     }

Properties

Name Value
svn:eol-style native
svn:keywords Id