ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/zoe/trunk/Matcher.cpp
Revision: 10
Committed: 2004-07-10T17:01:15-07:00 (20 years, 11 months ago) by douglas
File size: 1283 byte(s)
Log Message:
C++ified Matcher.

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 10 Matcher::Matcher(const ext::String& expression) : expression(NULL)
10 douglas 5 {
11     (*this)(expression);
12     }
13    
14     Matcher::~Matcher()
15     {
16     if (expression != NULL)
17     {
18     pcre_free(expression);
19     }
20     }
21    
22 douglas 7 bool Matcher::match(const ext::String& stuff)
23 douglas 5 {
24     substrings.clear();
25    
26     if (expression != NULL)
27     {
28     int length;
29    
30     pcre_fullinfo(expression, NULL, PCRE_INFO_CAPTURECOUNT, &length);
31    
32 douglas 10 int* substrings(new int[(++length *= 3)]);
33     int count(pcre_exec(expression, NULL, stuff.c_str(), stuff.length(), 0, 0,
34     substrings, length));
35 douglas 5
36     if (count > 0)
37     {
38 douglas 10 char* substring(new char[stuff.length() + 1]);
39 douglas 5
40 douglas 10 for (int index(0); index < count; ++index)
41 douglas 5 {
42     pcre_copy_substring(stuff.c_str(), substrings, count, index,
43     substring, stuff.length() + 1);
44    
45     this->substrings.push_back(substring);
46     }
47    
48     delete [] substring;
49     delete [] substrings;
50     return true;
51     }
52    
53     delete [] substrings;
54     }
55    
56     return false;
57     }
58    
59 douglas 7 Matcher& Matcher::operator()(const ext::String& expression)
60 douglas 5 {
61     substrings.clear();
62    
63     if (this->expression != NULL)
64     {
65     pcre_free(this->expression);
66     }
67    
68     const char* error;
69     int offset;
70    
71     this->expression = pcre_compile(expression.c_str(), 0, &error,
72     &offset, NULL);
73    
74     return *this;
75     }

Properties

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