ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Matcher/STL/Matcher.cpp
Revision: 390
Committed: 2004-12-24T04:09:17-08:00 (20 years, 5 months ago) by douglas
File size: 1142 byte(s)
Log Message:
Synchronize!

File Contents

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

Properties

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