4 * @brief Declaration file for FilterList.
10 #include <Poco/RegularExpression.h>
14 * @brief Container for one filtering rule / compiled expression.
15 * This structure holds compiled regular expression and a original expression
16 * as a string. We need the original expression string in case we want to
17 * know which regular expression did match.
21 std::string filterAsString; /** Original regular expression string */
22 Poco::RegularExpression regexp; /**< Compiled regular expression */
23 int _reOpts; /**< Options to set to Poco::RegularExpression */
24 filter_item(const std::string &filter, int reOpts) : filterAsString(filter), regexp(filter, reOpts), _reOpts(reOpts) {}
25 filter_item(const filter_item* item) : filterAsString(item->filterAsString), regexp(item->filterAsString, item->_reOpts), _reOpts(item->_reOpts) {}
28 typedef std::shared_ptr<filter_item> filter_item_ptr;
31 * @brief Regular expression list.
32 * This class holds a list of regular expressions for matching strings.
33 * The class also provides simple function for matching and remembers the
34 * last matched expression.
42 void AddRegExp(const std::string& regularExpression, bool exclude = false);
43 void RemoveAllFilters();
44 bool HasRegExps() const;
45 bool Match(const std::string& string, int codepage = ucr::CP_UTF_8);
46 void CloneFrom(const FilterList* filterList);
49 std::vector <filter_item_ptr> m_list;
50 std::vector <filter_item_ptr> m_listExclude;
55 * @brief Removes all expressions from the list.
57 inline void FilterList::RemoveAllFilters()
60 m_listExclude.clear();
64 * @brief Returns if list has any expressions.
65 * @return true if list contains one or more expressions.
67 inline bool FilterList::HasRegExps() const
69 return !m_list.empty() || !m_listExclude.empty();