ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Matcher/STL/Matcher.hpp
Revision: 327
Committed: 2004-12-13T20:10:39-08:00 (20 years, 6 months ago) by douglas
File size: 1320 byte(s)
Log Message:
Copy that!

File Contents

# Content
1 // 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 int options;
28 static int defaults;
29 Matcher(int options = defaults) : expression(NULL), options(options) {}
30 Matcher(const std::string& expression, int options = defaults) : expression(NULL), options(options) { (*this)(expression); }
31 ~Matcher() { if (expression != NULL) ::pcre_free(expression); }
32 bool match(const std::string& stuff);
33 std::vector<std::string>::size_type size() const { return substrings.size(); }
34 Matcher& operator()(const std::string& expression);
35 const std::string& operator[](std::vector<std::string>::size_type index) const { return substrings[index]; }
36 operator std::string() const { return substrings[0]; }
37 bool operator==(const std::string& stuff) { return match(stuff); }
38 bool operator!=(const std::string& stuff) { return !match(stuff); }
39 // friends:
40 friend bool operator==(const std::string& stuff, Matcher& matcher) { return matcher == stuff; }
41 friend bool operator!=(const std::string& stuff, Matcher& matcher) { return matcher != stuff; }
42 };
43
44 #endif // _Matcher_hpp_

Properties

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