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

Comparing:
Bender/Matcher.cpp (file contents), Revision 115 by Douglas Thrift, 2004-03-16T22:53:38-08:00 vs.
Matcher/Menes/Matcher.cpp (file contents), Revision 324 by douglas, 2004-12-13T19:40:34-08:00

# Line 1 | Line 1
1 < // Bender
1 > // Matcher
2   //
3   // Douglas Thrift
4   //
# 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 < }
9 > #ifdef _WIN32
10 > #pragma warning(disable:4267)
11 > #endif
12  
13 < Matcher::~Matcher()
13 > bool Matcher::match(const ext::String& stuff)
14   {
15 <        if (this->expression != NULL)
19 <        {
20 <                pcre_free(this->expression);
21 <        }
22 < }
15 >        substrings.Clear();
16  
17 < bool Matcher::match(const string& stuff)
25 < {
26 <        substrings.clear();
27 <        
28 <        if (this->expression != NULL)
17 >        if (expression != NULL)
18          {
19                  int length;
20  
21 <                pcre_fullinfo(expression, NULL, PCRE_INFO_CAPTURECOUNT, &length);
21 >                ::pcre_fullinfo(expression, NULL, PCRE_INFO_CAPTURECOUNT, &length);
22 >
23 >                int* substrings(new int[++length *= 3]), count(::pcre_exec(expression, NULL, stuff.GetData().Begin(), stuff.GetData().GetSize(), 0, 0, substrings, length));
24  
34                int* substrings = new int[(++length *= 3)];
35                int count = pcre_exec(expression, NULL, stuff.c_str(), stuff.length(),
36                        0, 0, substrings, length);
37                
25                  if (count > 0)
26                  {
27 <                        char* substring = new char[stuff.length() + 1];
27 >                        char* substring(new char[stuff.GetData().GetSize() + 1]);
28  
29 <                        for (int index = 0; index < count; index++)
29 >                        for (int index(0); index < count; ++index)
30                          {
31 <                                pcre_copy_substring(stuff.c_str(), substrings, count, index,
45 <                                        substring, stuff.length() + 1);
31 >                                ::pcre_copy_substring(stuff.GetData().Begin(), substrings, count, index, substring, stuff.GetData().GetSize() + 1);
32  
33 <                                this->substrings.push_back(substring);
33 >                                this->substrings.InsertLast(substring);
34                          }
35  
36                          delete [] substring;
37                          delete [] substrings;
38 +
39                          return true;
40                  }
41  
# Line 58 | Line 45 | bool Matcher::match(const string& stuff)
45          return false;
46   }
47  
48 < Matcher& Matcher::operator()(const string& expression)
48 > Matcher& Matcher::operator()(const ext::String& expression)
49   {
50 <        substrings.clear();
51 <        
52 <        if (this->expression != NULL)
53 <        {
54 <                pcre_free(this->expression);
55 <        }
50 >        substrings.Clear();
51 >
52 >        if (this->expression != NULL) ::pcre_free(this->expression);
53 >
54 >        const char* error;
55 >        int offset;
56  
57 <        this->expression = pcre_compile(expression.c_str(), PCRE_MULTILINE, NULL,
71 <                NULL, NULL);
57 >        this->expression = ::pcre_compile(expression.NullTerminate(), PCRE_MULTILINE, &error, &offset, NULL);
58  
59          return *this;
60   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines