ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Bender/Matcher.cpp
Revision: 266
Committed: 2004-10-27T04:14:56-07:00 (20 years, 8 months ago) by Douglas Thrift
File size: 1138 byte(s)
Log Message:
Wow!

File Contents

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

Properties

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