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

Comparing Bender/Matcher.cpp (file contents):
Revision 265 by Douglas Thrift, 2004-03-17T21:15:24-08:00 vs.
Revision 266 by Douglas Thrift, 2004-10-27T04:14:56-07:00

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines