ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Iffy/Matcher.hpp
Revision: 309
Committed: 2004-12-12T23:44:14-08:00 (20 years, 6 months ago) by douglas
File size: 1100 byte(s)
Log Message:
Works on Windows! Except for console input.

File Contents

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

Properties

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