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

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 Matcher() : expression(NULL) {}
28 Matcher(const ext::String& expression) : expression(NULL) { (*this)(expression); }
29 ~Matcher() { if (expression != NULL) pcre_free(expression); }
30 bool match(const ext::String& stuff);
31 size_t size(void) const { return substrings.GetSize(); }
32 Matcher& operator()(const ext::String& expression);
33 const ext::String& operator[](unsigned index) const { return substrings[index]; }
34 operator ext::String() const { return substrings[0]; }
35 bool operator==(const ext::String& stuff) { return match(stuff); }
36 bool operator!=(const ext::String& stuff) { return !match(stuff); }
37 // friends:
38 friend bool operator==(const ext::String& stuff, Matcher& matcher) { return matcher == stuff; }
39 friend bool operator!=(const ext::String& stuff, Matcher& matcher) { return matcher != stuff; }
40 };
41
42 #endif // _Matcher_hpp_

Properties

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