// Zoe AIM Away Message RSS Feed Generator // // Douglas Thrift // // $Id$ #include "Matcher.hpp" bool Matcher::match(const ext::String& stuff) { substrings.clear(); if (expression != NULL) { int length; pcre_fullinfo(expression, NULL, PCRE_INFO_CAPTURECOUNT, &length); int* substrings(new int[(++length *= 3)]); int count(pcre_exec(expression, NULL, stuff.NullTerminate(), stuff.GetSize(), 0, 0, substrings, length)); if (count > 0) { char* substring(new char[stuff.length() + 1]); for (int index(0); index < count; ++index) { pcre_copy_substring(stuff.NullTerminate(), substrings, count, index, substring, stuff.GetSize() + 1); this->substrings.push_back(substring); } delete [] substring; delete [] substrings; return true; } delete [] substrings; } return false; } Matcher& Matcher::operator()(const ext::String& expression) { substrings.clear(); if (this->expression != NULL) pcre_free(this->expression); const char* error; int offset; this->expression = pcre_compile(expression.NullTerminate(), 0, &error, &offset, NULL); return *this; }