4 * @brief Implementation file for FilterList.
8 #include "FilterList.h"
10 #include <Poco/RegularExpression.h>
13 using Poco::RegularExpression;
18 FilterList::FilterList()
19 : m_lastMatchExpression(nullptr)
26 FilterList::~FilterList()
32 * @brief Add new regular expression to the list.
33 * This function adds new regular expression to the list of expressions.
34 * The regular expression is compiled and studied for better performance.
35 * @param [in] regularExpression Regular expression string.
36 * @param [in] encoding Expression encoding.
38 void FilterList::AddRegExp(const std::string& regularExpression)
42 m_list.push_back(filter_item_ptr(new filter_item(regularExpression, RegularExpression::RE_UTF8)));
51 * @brief Match string against list of expressions.
52 * This function matches given @p string against the list of regular
53 * expressions. The matching ends when first match is found, so all
54 * expressions may not be matched against.
55 * @param [in] string string to match.
56 * @param [in] codepage codepage of string.
57 * @return true if any of the expressions did match the string.
59 bool FilterList::Match(const std::string& string, int codepage/*=CP_UTF8*/)
62 const size_t count = m_list.size();
64 // convert string into UTF-8
65 ucr::buffer buf(string.length() * 2);
67 if (codepage != ucr::CP_UTF_8)
68 ucr::convert(ucr::NONE, codepage, reinterpret_cast<const unsigned char *>(string.c_str()),
69 string.length(), ucr::UTF8, ucr::CP_UTF_8, &buf);
72 while (i < count && !retval)
74 const filter_item_ptr& item = m_list[i];
76 RegularExpression::Match match;
80 result = item->regexp.match(std::string(reinterpret_cast<const char *>(buf.ptr), buf.size), 0, match);
82 result = item->regexp.match(string, 0, match);
90 m_lastMatchExpression = &item->filterAsString;