ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/SiteMapper/Matcher.cpp
(Generate patch)

Comparing SiteMapper/Matcher.cpp (file contents):
Revision 284 by Douglas Thrift, 2004-03-25T18:04:04-08:00 vs.
Revision 285 by douglas, 2004-11-28T03:01:11-08:00

# Line 6 | Line 6
6  
7   #include "Matcher.hpp"
8  
9 < Matcher::Matcher(const string& expression)
9 > bool Matcher::match(const ext::String& stuff)
10   {
11 <        this->expression = NULL;
12 <
13 <        (*this)(expression);
14 < }
15 <
16 < Matcher::~Matcher()
17 < {
18 <        if (expression != NULL)
19 <        {
20 <                pcre_free(expression);
21 <        }
22 < }
23 <
24 < bool Matcher::match(const string& stuff)
25 < {
26 <        substrings.clear();
11 >        substrings.Clear();
12  
13          if (expression != NULL)
14          {
15                  int length;
16  
17 <                pcre_fullinfo(expression, NULL, PCRE_INFO_CAPTURECOUNT, &length);
17 >                ::pcre_fullinfo(expression, NULL, PCRE_INFO_CAPTURECOUNT, &length);
18  
19 <                int* substrings = new int[(++length *= 3)];
20 <                int count = pcre_exec(expression, NULL, stuff.c_str(), stuff.length(),
36 <                        0, 0, substrings, length);
19 >                int* substrings(new int[(++length *= 3)]);
20 >                int count(::pcre_exec(expression, NULL, stuff.NullTerminate(), stuff.GetSize(), 0, 0, substrings, length));
21  
22                  if (count > 0)
23                  {
24 <                        char* substring = new char[stuff.length() + 1];
24 >                        char* substring(new char[stuff.GetSize() + 1]);
25  
26 <                        for (int index = 0; index < count; index++)
26 >                        for (int index(0); index < count; ++index)
27                          {
28 <                                pcre_copy_substring(stuff.c_str(), substrings, count, index,
45 <                                        substring, stuff.length() + 1);
28 >                                ::pcre_copy_substring(stuff.NullTerminate(), substrings, count, index, substring, stuff.GetSize() + 1);
29  
30 <                                this->substrings.push_back(substring);
30 >                                this->substrings.InsertLast(substring);
31                          }
32  
33                          delete [] substring;
34                          delete [] substrings;
35 +
36                          return true;
37                  }
38  
# Line 58 | Line 42 | bool Matcher::match(const string& stuff)
42          return false;
43   }
44  
45 < Matcher& Matcher::operator()(const string& expression)
45 > Matcher& Matcher::operator()(const ext::String& expression)
46   {
47 <        substrings.clear();
47 >        substrings.Clear();
48  
49 <        if (this->expression != NULL)
66 <        {
67 <                pcre_free(this->expression);
68 <        }
49 >        if (this->expression != NULL) ::pcre_free(this->expression);
50  
51          const char* error;
52          int offset;
53  
54 <        this->expression = pcre_compile(expression.c_str(), PCRE_UNGREEDY |
74 <                PCRE_DOTALL, &error, &offset, NULL);
54 >        this->expression = pcre_compile(expression.NullTerminate(), PCRE_UNGREEDY | PCRE_DOTALL, &error, &offset, NULL);
55  
56          return *this;
57   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines