ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/SiteMapper/Matcher.cpp
Revision: 304
Committed: 2004-12-12T21:52:24-08:00 (20 years, 6 months ago) by douglas
File size: 1149 byte(s)
Log Message:
Hmm.

File Contents

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

Properties

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