ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Matcher/Menes/Matcher.hpp
Revision: 426
Committed: 2005-03-22T20:29:27-08:00 (20 years, 3 months ago) by douglas
File size: 1329 byte(s)
Log Message:
Yeah, so!

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/exception.hpp>
17 #include <menes-ext/string.hpp>
18 #include <menes-ext/vector.hpp>
19
20 #include <pcre.h>
21
22 class Matcher
23 {
24 private:
25 ::pcre* expression;
26 ext::Vector<ext::String> substrings;
27 public:
28 int options;
29 static int defaults;
30 Matcher(int options = defaults) : expression(NULL), options(options) {}
31 Matcher(const ext::String& expression, int options = defaults) : expression(NULL), options(options) { (*this)(expression); }
32 ~Matcher() { if (expression != NULL) ::pcre_free(expression); }
33 bool match(const ext::String& stuff);
34 size_t size() const { return substrings.GetSize(); }
35 Matcher& operator()(const ext::String& expression);
36 const ext::String& operator[](size_t index) const { return substrings[index]; }
37 operator ext::String() const { return substrings[0]; }
38 bool operator==(const ext::String& stuff) { return match(stuff); }
39 bool operator!=(const ext::String& stuff) { return !match(stuff); }
40 // friends:
41 friend bool operator==(const ext::String& stuff, Matcher& matcher) { return matcher == stuff; }
42 friend bool operator!=(const ext::String& stuff, Matcher& matcher) { return matcher != stuff; }
43 };
44
45 #endif//_Matcher_hpp_

Properties

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