// Matcher STL // // Douglas Thrift // // $Id$ #ifndef _Matcher_hpp_ #define _Matcher_hpp_ #if defined(_MSC_VER) #if _MSC_VER > 1000 #pragma once #endif #endif #include #include #include class Matcher { private: ::pcre* expression; std::vector substrings; public: int options; static int defaults; Matcher(int options = defaults) : expression(NULL), options(options) {} Matcher(const std::string& expression, int options = defaults) : expression(NULL), options(options) { (*this)(expression); } ~Matcher() { if (expression != NULL) ::pcre_free(expression); } bool match(const std::string& stuff); std::vector::size_type size() const { return substrings.size(); } Matcher& operator()(const std::string& expression); const std::string& operator[](std::vector::size_type index) const { return substrings[index]; } operator std::string() const { return substrings[0]; } bool operator==(const std::string& stuff) { return match(stuff); } bool operator!=(const std::string& stuff) { return !match(stuff); } // friends: friend bool operator==(const std::string& stuff, Matcher& matcher) { return matcher == stuff; } friend bool operator!=(const std::string& stuff, Matcher& matcher) { return matcher != stuff; } }; #endif // _Matcher_hpp_