46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
#include "textfilter.h"
|
|
|
|
#include <util.h> // 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 {
|
|
if(ignoreCase)
|
|
return matchesIC(m.text, text);
|
|
else
|
|
return matches(m.text, text);
|
|
}
|
|
|
|
void RegexFilter::setup(std::ostream& o, std::istream& str) {
|
|
//build regex pattern
|
|
std::string text = ""; //TODO
|
|
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 std::regex_search(m.text, pattern);
|
|
} |