// Matcher STL // // Douglas Thrift // // $Id$ #include "Matcher.hpp" #ifdef _WIN32 #pragma warning(disable:4267) #endif bool Matcher::match(const std::string& stuff) { substrings.clear(); if (expression != NULL) { int length; ::pcre_fullinfo(expression, NULL, PCRE_INFO_CAPTURECOUNT, &length); int* substrings(new int[++length *= 3]), count(::pcre_exec(expression, NULL, stuff.data(), stuff.size(), 0, 0, substrings, length)); if (count > 0) { char* substring(new char[stuff.size() + 1]); for (int index(0); index < count; ++index) { ::pcre_copy_substring(stuff.data(), substrings, count, index, substring, stuff.size() + 1); this->substrings.push_back(substring); } delete [] substring; delete [] substrings; return true; } delete [] substrings; } return false; } int Matcher::defaults(0); Matcher& Matcher::operator()(const std::string& expression) { substrings.clear(); if (this->expression != NULL) ::pcre_free(this->expression); const char* error; int offset; this->expression = ::pcre_compile(expression.c_str(), options, &error, &offset, NULL); return *this; }