aboutsummaryrefslogtreecommitdiff
path: root/lib/urlfilter/adblock
diff options
context:
space:
mode:
Diffstat (limited to 'lib/urlfilter/adblock')
-rw-r--r--lib/urlfilter/adblock/adblocklist.cpp44
-rw-r--r--lib/urlfilter/adblock/parser.cpp26
2 files changed, 35 insertions, 35 deletions
diff --git a/lib/urlfilter/adblock/adblocklist.cpp b/lib/urlfilter/adblock/adblocklist.cpp
index c749e9e..3be21bd 100644
--- a/lib/urlfilter/adblock/adblocklist.cpp
+++ b/lib/urlfilter/adblock/adblocklist.cpp
@@ -71,7 +71,7 @@ void AdBlockList::parseLine(const QString& line)
if(parsedLine.isEmpty())
return;
- if(parsedLine.startsWith(QLatin1Literal("!"))) {
+ if(parsedLine.startsWith(QLatin1String("!"))) {
const auto comment = parseComment(parsedLine);
if(comment) {
@@ -84,7 +84,7 @@ void AdBlockList::parseLine(const QString& line)
}
// css rule -> filterleaves cannot do element blocking
- if(parsedLine.contains(QLatin1Literal("##")) || parsedLine.contains(QLatin1Literal("#@#"))) {
+ if(parsedLine.contains(QLatin1String("##")) || parsedLine.contains(QLatin1String("#@#"))) {
qDebug("TODO: %s", qUtf8Printable(parsedLine));
return;
}
@@ -93,7 +93,7 @@ void AdBlockList::parseLine(const QString& line)
r.action = UrlFilter::Block;
// exception rules
- if(parsedLine.startsWith(QLatin1Literal("@@"))) {
+ if(parsedLine.startsWith(QLatin1String("@@"))) {
r.action = UrlFilter::Allow;
parsedLine.remove(0, 2);
}
@@ -102,24 +102,24 @@ void AdBlockList::parseLine(const QString& line)
// parse options
{
- const int sepPos = parsedLine.indexOf(QLatin1Literal("$"));
+ const int sepPos = parsedLine.indexOf(QLatin1String("$"));
if(sepPos != -1) {
- const auto options = parsedLine.mid(sepPos + 1).split(QLatin1Literal(","));
+ const auto options = parsedLine.mid(sepPos + 1).split(QLatin1String(","));
parsedLine = parsedLine.mid(0, sepPos);
for(const QString &option : options) {
- if(option.startsWith(QLatin1Literal("domain"))) {
- const auto domainList = option.mid(7).split(QLatin1Literal("|"));
+ if(option.startsWith(QLatin1String("domain"))) {
+ const auto domainList = option.mid(7).split(QLatin1String("|"));
for(const QString &domain : domainList) {
- if(domain.startsWith(QLatin1Literal("~"))) {
+ if(domain.startsWith(QLatin1String("~"))) {
r.disabledOn.append(domain.mid(1));
} else {
r.enabledOn.append(domain);
}
}
- } else if(option.endsWith(QLatin1Literal("match-case"))) {
- matchCase = !option.startsWith(QLatin1Literal("~"));
+ } else if(option.endsWith(QLatin1String("match-case"))) {
+ matchCase = !option.startsWith(QLatin1String("~"));
} else {
const auto pair = parseResourceOption(option);
@@ -130,26 +130,26 @@ void AdBlockList::parseLine(const QString& line)
}
}
- if(parsedLine.startsWith(QLatin1Literal("/")) && parsedLine.endsWith(QLatin1Literal("/"))) {
+ if(parsedLine.startsWith(QLatin1String("/")) && parsedLine.endsWith(QLatin1String("/"))) {
// regular expression rule
parsedLine = parsedLine.mid(1, parsedLine.length() - 2);
r.matcher = new ContentsMatcher<QRegularExpression>(parsedLine, UrlFilter::RegularExpressionMatch);
- } else if(parsedLine.startsWith(QLatin1Literal("||")) && parsedLine.endsWith(QLatin1Literal("^"))) {
+ } else if(parsedLine.startsWith(QLatin1String("||")) && parsedLine.endsWith(QLatin1String("^"))) {
parsedLine = parsedLine.mid(2, parsedLine.length() - 3);
r.matcher = new ContentsMatcher<QString>(parsedLine, UrlFilter::DomainMatch);
- } else if(parsedLine.startsWith(QLatin1Literal("|")) && parsedLine.endsWith(QLatin1Literal("|"))) {
+ } else if(parsedLine.startsWith(QLatin1String("|")) && parsedLine.endsWith(QLatin1String("|"))) {
// string equals rule
parsedLine = parsedLine.mid(1, parsedLine.length() - 2);
r.matcher = new ContentsMatcher<QStringMatcher>(parsedLine, UrlFilter::StringEquals);
- } else if(parsedLine.startsWith(QLatin1Literal("||"))) {
+ } else if(parsedLine.startsWith(QLatin1String("||"))) {
// string starts with rule
parsedLine = parsedLine.mid(2);
r.matcher = new ContentsMatcher<QStringMatcher>(parsedLine, UrlFilter::StringStartsWith);
- } else if(parsedLine.endsWith(QLatin1Literal("|"))) {
+ } else if(parsedLine.endsWith(QLatin1String("|"))) {
// string ends with rule
parsedLine.chop(1);
r.matcher = new ContentsMatcher<QStringMatcher>(parsedLine, UrlFilter::StringEndsWith);
@@ -158,20 +158,20 @@ void AdBlockList::parseLine(const QString& line)
// generic contains rule
// remove beginning and ending wildcards
- if(parsedLine.startsWith(QLatin1Literal("*")))
+ if(parsedLine.startsWith(QLatin1String("*")))
parsedLine = parsedLine.mid(1);
- if(parsedLine.endsWith(QLatin1Literal("*")))
+ if(parsedLine.endsWith(QLatin1String("*")))
parsedLine.chop(1);
- if(parsedLine.contains(QLatin1Literal("*")) || parsedLine.contains(QLatin1Literal("^"))) {
+ if(parsedLine.contains(QLatin1String("*")) || parsedLine.contains(QLatin1String("^"))) {
// check for wildcards and translate to regexp
// wildcard "*" - any number of characters
// separator "^" - end, ? or /
- parsedLine.replace(QLatin1Literal("||"), QLatin1Literal("^\\w+://"));
- parsedLine.replace(QLatin1Literal("|"), QLatin1Literal("\\|"));
- parsedLine.replace(QLatin1Literal("*"), QLatin1Literal(".*"));
- parsedLine.replace(QLatin1Literal("^"), QLatin1Literal("($|\\?|\\/)"));
+ parsedLine.replace(QLatin1String("||"), QLatin1String("^\\w+://"));
+ parsedLine.replace(QLatin1String("|"), QLatin1String("\\|"));
+ parsedLine.replace(QLatin1String("*"), QLatin1String(".*"));
+ parsedLine.replace(QLatin1String("^"), QLatin1String("($|\\?|\\/)"));
r.matcher = new ContentsMatcher<QRegularExpression>(parsedLine, UrlFilter::RegularExpressionMatch);
diff --git a/lib/urlfilter/adblock/parser.cpp b/lib/urlfilter/adblock/parser.cpp
index d65a2e4..68f895d 100644
--- a/lib/urlfilter/adblock/parser.cpp
+++ b/lib/urlfilter/adblock/parser.cpp
@@ -20,53 +20,53 @@ std::optional<std::pair<QString, QString>> parseComment(QString &line)
std::optional<std::pair<QWebEngineUrlRequestInfo::ResourceType, bool>> parseResourceOption(const QString &option)
{
- const bool exception = !option.startsWith(QLatin1Literal("~"));
+ const bool exception = !option.startsWith(QLatin1String("~"));
- if(option.endsWith(QLatin1Literal("script"))) {
+ if(option.endsWith(QLatin1String("script"))) {
// external scripts loaded via HTML script tag
return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeScript, exception);
- } else if(option.endsWith(QLatin1Literal("image"))) {
+ } else if(option.endsWith(QLatin1String("image"))) {
// regular images, typically loaded via HTML img tag
return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeImage, exception);
- } else if(option.endsWith(QLatin1Literal("stylesheet"))) {
+ } else if(option.endsWith(QLatin1String("stylesheet"))) {
// external CSS stylesheet files
return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeStylesheet, exception);
- } else if(option.endsWith(QLatin1Literal("object"))) {
+ } else if(option.endsWith(QLatin1String("object"))) {
// content handled by browser plugins, e.g. Flash or Java
return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeObject, exception);
- } else if(option.endsWith(QLatin1Literal("xmlhttprequest"))) {
+ } else if(option.endsWith(QLatin1String("xmlhttprequest"))) {
// requests started using the XMLHttpRequest object or fetch() API
return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeXhr, exception);
- } else if(option.endsWith(QLatin1Literal("object-subrequest"))) {
+ } else if(option.endsWith(QLatin1String("object-subrequest"))) {
// requests started by plugins like Flash
return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypePluginResource, exception);
- } else if(option.endsWith(QLatin1Literal("subdocument"))) {
+ } else if(option.endsWith(QLatin1String("subdocument"))) {
// embedded pages, usually included via HTML frames
return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeSubFrame, exception);
- } else if(option.endsWith(QLatin1Literal("ping"))) {
+ } else if(option.endsWith(QLatin1String("ping"))) {
// requests started by <a ping> or navigator.sendBeacon()
return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypePing, exception);
- } else if(option.endsWith(QLatin1Literal("websocket"))) {
+ } else if(option.endsWith(QLatin1String("websocket"))) {
// requests initiated via WebSocket object
qDebug("Resource type 'websocket' not available");
- } else if(option.endsWith(QLatin1Literal("webrtc"))) {
+ } else if(option.endsWith(QLatin1String("webrtc"))) {
// connections opened via RTCPeerConnection instances to ICE servers
qDebug("Resource type 'webrtc' not available");
- } else if(option.endsWith(QLatin1Literal("document"))) {
+ } else if(option.endsWith(QLatin1String("document"))) {
// the page itself
return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeMainFrame, exception);
- } else if(option.endsWith(QLatin1Literal("other"))) {
+ } else if(option.endsWith(QLatin1String("other"))) {
return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeUnknown, exception);
}