ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/FeepingCreaturism/Matcher.cpp
Revision: 235
Committed: 2004-09-10T16:08:12-07:00 (20 years, 9 months ago) by Douglas Thrift
File size: 1137 byte(s)
Log Message:
Jay says this is more correct.

File Contents

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

Properties

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