ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Matcher/Menes/Matcher.cpp
Revision: 334
Committed: 2004-12-13T21:10:06-08:00 (20 years, 6 months ago) by douglas
File size: 1208 byte(s)
Log Message:
Hmm?

File Contents

# User Rev Content
1 douglas 317 // Matcher
2 Douglas Thrift 113 //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     #include "Matcher.hpp"
8    
9 douglas 319 #ifdef _WIN32
10     #pragma warning(disable:4267)
11     #endif
12    
13 Douglas Thrift 266 bool Matcher::match(const ext::String& stuff)
14 Douglas Thrift 115 {
15 douglas 305 substrings.Clear();
16 Douglas Thrift 119
17     if (expression != NULL)
18 Douglas Thrift 115 {
19     int length;
20 Douglas Thrift 113
21 douglas 324 ::pcre_fullinfo(expression, NULL, PCRE_INFO_CAPTURECOUNT, &length);
22 Douglas Thrift 115
23 douglas 324 int* substrings(new int[++length *= 3]), count(::pcre_exec(expression, NULL, stuff.GetData().Begin(), stuff.GetData().GetSize(), 0, 0, substrings, length));
24 Douglas Thrift 119
25 Douglas Thrift 115 if (count > 0)
26     {
27 Douglas Thrift 266 char* substring(new char[stuff.GetData().GetSize() + 1]);
28 Douglas Thrift 115
29 Douglas Thrift 266 for (int index(0); index < count; ++index)
30 Douglas Thrift 115 {
31 douglas 324 ::pcre_copy_substring(stuff.GetData().Begin(), substrings, count, index, substring, stuff.GetData().GetSize() + 1);
32 Douglas Thrift 115
33 douglas 305 this->substrings.InsertLast(substring);
34 Douglas Thrift 115 }
35    
36     delete [] substring;
37     delete [] substrings;
38 Douglas Thrift 266
39 Douglas Thrift 115 return true;
40     }
41    
42     delete [] substrings;
43     }
44    
45 Douglas Thrift 113 return false;
46     }
47 Douglas Thrift 114
48 douglas 334 int Matcher::defaults(0);
49 douglas 325
50 Douglas Thrift 266 Matcher& Matcher::operator()(const ext::String& expression)
51 Douglas Thrift 114 {
52 douglas 305 substrings.Clear();
53 Douglas Thrift 119
54 douglas 324 if (this->expression != NULL) ::pcre_free(this->expression);
55 Douglas Thrift 114
56 Douglas Thrift 116 const char* error;
57     int offset;
58 Douglas Thrift 115
59 douglas 325 this->expression = ::pcre_compile(expression.NullTerminate(), options, &error, &offset, NULL);
60 Douglas Thrift 116
61 Douglas Thrift 114 return *this;
62     }

Properties

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