ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Matcher/STL/Matcher.hpp
Revision: 324
Committed: 2004-12-13T19:40:34-08:00 (20 years, 6 months ago) by douglas
File size: 1202 byte(s)
Log Message:
Hello!

File Contents

# User Rev Content
1 douglas 324 // Matcher STL
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     #ifndef _Matcher_hpp_
8     #define _Matcher_hpp_
9    
10     #if defined(_MSC_VER)
11     #if _MSC_VER > 1000
12     #pragma once
13     #endif
14     #endif
15    
16     #include <string>
17     #include <vector>
18    
19     #include <pcre.h>
20    
21     class Matcher
22     {
23     private:
24     ::pcre* expression;
25     std::vector<std::string> substrings;
26     public:
27     Matcher() : expression(NULL) {}
28     Matcher(const std::string& expression) : expression(NULL) { (*this)(expression); }
29     ~Matcher() { if (expression != NULL) ::pcre_free(expression); }
30     bool match(const std::string& stuff);
31     std::vector<std::string>::size_type size() const { return substrings.size(); }
32     Matcher& operator()(const std::string& expression);
33     const std::string& operator[](std::vector<std::string>::size_type index) const { return substrings[index]; }
34     operator std::string() const { return substrings[0]; }
35     bool operator==(const std::string& stuff) { return match(stuff); }
36     bool operator!=(const std::string& stuff) { return !match(stuff); }
37     // friends:
38     friend bool operator==(const std::string& stuff, Matcher& matcher) { return matcher == stuff; }
39     friend bool operator!=(const std::string& stuff, Matcher& matcher) { return matcher != stuff; }
40     };
41    
42     #endif // _Matcher_hpp_

Properties

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