aboutsummaryrefslogtreecommitdiff
path: root/lib/urlfilter/formats/adblockrule.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/urlfilter/formats/adblockrule.h')
-rw-r--r--lib/urlfilter/formats/adblockrule.h26
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/urlfilter/formats/adblockrule.h b/lib/urlfilter/formats/adblockrule.h
index 3331cac..6be3cdf 100644
--- a/lib/urlfilter/formats/adblockrule.h
+++ b/lib/urlfilter/formats/adblockrule.h
@@ -14,24 +14,35 @@
#include <QRegularExpression>
#include <QStringMatcher>
+class Matcher
+{
+public:
+ virtual bool hasMatch(const QString &where) const = 0;
+};
+
template <typename T>
-class ContentsMatcher
+class ContentsMatcher : public Matcher
{
public:
ContentsMatcher(const QString &pattern, FilterLeaf::UrlMatchType matchType)
{
this->matchType = matchType;
patternLength = pattern.length();
- matcher.setPattern(pattern);
+
if constexpr(std::is_same_v<T, QRegularExpression>) {
matcher.setPatternOptions(matcher.patternOptions() | QRegularExpression::CaseInsensitiveOption);
+ matcher.setPattern(pattern);
} else if constexpr(std::is_same_v<T, QStringMatcher>) {
matcher.setCaseSensitivity(Qt::CaseInsensitive);
+ matcher.setPattern(pattern);
+ } else if constexpr(std::is_same_v<T, QString>) {
+ matcher = QUrl::fromUserInput(pattern).host();
+// qDebug("matcher: %s", qUtf8Printable(matcher));
}
}
- bool hasMatch(const QString &where) const
+ bool hasMatch(const QString &where) const override
{
if constexpr(std::is_same_v<T, QStringMatcher>) {
switch (matchType) {
@@ -58,6 +69,13 @@ public:
if(matchType != FilterLeaf::RegularExpressionMatch)
qWarning("ContentsMatcher is a regular expression, but not doing a regular expression match!");
return matcher.match(where).hasMatch();
+ } else if constexpr(std::is_same_v<T, QString>) {
+ // TODO: fix
+ if(matchType == FilterLeaf::DomainMatch) {
+// qDebug("matching %s", qUtf8Printable(QUrl(where).host()));
+ return QUrl(where).host().endsWith(matcher);
+ } else
+ return matcher == where;
} else {
qWarning("Matcher has no backend, returning false");
return false;
@@ -65,7 +83,7 @@ public:
}
private:
- int patternLength;
+ int patternLength;
T matcher;
FilterLeaf::UrlMatchType matchType;
};