// Matcher // // Douglas Thrift // // $Id$ #ifndef _Matcher_hpp_ #define _Matcher_hpp_ #include #ifdef MENES_PRAGMA_ONCE #pragma once #endif #include #include #include #include class Matcher { private: ::pcre* expression; ext::Vector substrings; public: int options; static int defaults; Matcher(int options = defaults) : expression(NULL), options(options) {} Matcher(const ext::String& expression, int options = defaults) : expression(NULL), options(options) { (*this)(expression); } ~Matcher() { if (expression != NULL) ::pcre_free(expression); } bool match(const ext::String& stuff); size_t size() const { return substrings.GetSize(); } Matcher& operator()(const ext::String& expression); const ext::String& operator[](size_t index) const { return substrings[index]; } operator ext::String() const { return substrings[0]; } bool operator==(const ext::String& stuff) { return match(stuff); } bool operator!=(const ext::String& stuff) { return !match(stuff); } // friends: friend bool operator==(const ext::String& stuff, Matcher& matcher) { return matcher == stuff; } friend bool operator!=(const ext::String& stuff, Matcher& matcher) { return matcher != stuff; } }; #endif//_Matcher_hpp_