pollymc/launcher/Filter.cpp

32 lines
776 B
C++
Raw Normal View History

2018-03-19 07:06:12 +05:30
#include "Filter.h"
Filter::~Filter(){}
ContainsFilter::ContainsFilter(const QString& pattern) : pattern(pattern){}
ContainsFilter::~ContainsFilter(){}
bool ContainsFilter::accepts(const QString& value)
{
2018-07-15 18:21:05 +05:30
return value.contains(pattern);
2018-03-19 07:06:12 +05:30
}
ExactFilter::ExactFilter(const QString& pattern) : pattern(pattern){}
ExactFilter::~ExactFilter(){}
bool ExactFilter::accepts(const QString& value)
{
return value == pattern;
2018-03-19 07:06:12 +05:30
}
RegexpFilter::RegexpFilter(const QString& regexp, bool invert)
2018-07-15 18:21:05 +05:30
:invert(invert)
2018-03-19 07:06:12 +05:30
{
2018-07-15 18:21:05 +05:30
pattern.setPattern(regexp);
pattern.optimize();
2018-03-19 07:06:12 +05:30
}
RegexpFilter::~RegexpFilter(){}
bool RegexpFilter::accepts(const QString& value)
{
2018-07-15 18:21:05 +05:30
auto match = pattern.match(value);
bool matched = match.hasMatch();
return invert ? (!matched) : (matched);
2018-03-19 07:06:12 +05:30
}