#include "textfilter.h" #include // mrbesen/util.h static bool matches(const std::string& msg, const std::string& text) { //simpler contains check return (msg.find(text) != std::string::npos); } static bool matchesIC(const std::string& msg, const std::string& text) { //turn compare string to lower std::string lower; mrbesen::util::toLower(msg, lower); return (lower.find(text) != std::string::npos); } void TextFilter::setup(std::ostream& o, std::istream& str) { o << "Such text:"; std::getline(str, text); Filter::setup(o, str); if(ignoreCase) { mrbesen::util::toLower(text); } } bool TextFilter::filter(const Message& m) const { return match(m.text); } bool TextFilter::match(const std::string& input) const { if(ignoreCase) return matchesIC(input, text); else return matches(input, text); } void RegexFilter::setup(std::ostream& o, std::istream& str) { //build regex pattern o << "Regexpattern: " << std::endl; std::string text; getline(str, text); pattern = std::regex(text, (ignoreCase ? std::regex::icase : (std::regex::flag_type) 0)); Filter::setup(o, str); } bool RegexFilter::filter(const Message& m) const { return match(m.text); } bool RegexFilter::match(const std::string& input) const { return std::regex_search(input, pattern); } bool FilenameFilter::filter(const Message& m) const { if(m.hasFile()) { return match(m.filename); } return false; } bool RegexFilenameFilter::filter(const Message& m) const { if(m.hasFile()) { return match(m.filename); } return false; }