1 |
// Iffy |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id$ |
6 |
|
7 |
#ifndef _Matcher_hpp_ |
8 |
#define _Matcher_hpp_ |
9 |
|
10 |
#include "Iffy.hpp" |
11 |
|
12 |
#ifdef MENES_PRAGMA_ONCE |
13 |
#pragma once |
14 |
#endif |
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 |
size_t size(void) const { return substrings.GetSize(); } |
29 |
Matcher& operator()(const ext::String& expression); |
30 |
const ext::String& operator[](size_t index) const { return substrings[index]; } |
31 |
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_ |