ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Matcher/Menes/Matcher.hpp
Revision: 331
Committed: 2004-12-13T20:49:48-08:00 (20 years, 6 months ago) by douglas
File size: 1295 byte(s)
Log Message:
Duh!

File Contents

# Content
1 // Matcher
2 //
3 // Douglas Thrift
4 //
5 // $Id$
6
7 #ifndef _Matcher_hpp_
8 #define _Matcher_hpp_
9
10 #include <menes/platform.hpp>
11
12 #ifdef MENES_PRAGMA_ONCE
13 #pragma once
14 #endif
15
16 #include <menes-ext/casts.hpp>
17 #include <menes-ext/string.hpp>
18
19 #include <pcre.h>
20
21 class Matcher
22 {
23 private:
24 ::pcre* expression;
25 ext::Vector<ext::String> substrings;
26 public:
27 int options;
28 static int defaults;
29 Matcher(int options = defaults) : expression(NULL), options(options) {}
30 Matcher(const ext::String& expression, int options = defaults) : expression(NULL), options(options) { (*this)(expression); }
31 ~Matcher() { if (expression != NULL) ::pcre_free(expression); }
32 bool match(const ext::String& stuff);
33 size_t size() const { return substrings.GetSize(); }
34 Matcher& operator()(const ext::String& expression);
35 const ext::String& operator[](size_t index) const { return substrings[index]; }
36 operator ext::String() const { return substrings[0]; }
37 bool operator==(const ext::String& stuff) { return match(stuff); }
38 bool operator!=(const ext::String& stuff) { return !match(stuff); }
39 // friends:
40 friend bool operator==(const ext::String& stuff, Matcher& matcher) { return matcher == stuff; }
41 friend bool operator!=(const ext::String& stuff, Matcher& matcher) { return matcher != stuff; }
42 };
43
44 #endif // _Matcher_hpp_

Properties

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