From cb30cee7a065a074394347f112451decc4847674 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 17 Jan 2020 20:25:44 +0200 Subject: Fix various gcc and clazy compile warnings --- lib/urlfilter/adblock/adblocklist.cpp | 44 +++++++++++++++++------------------ lib/urlfilter/adblock/parser.cpp | 26 ++++++++++----------- lib/urlfilter/hostlist/hostlist.cpp | 8 +++---- 3 files changed, 39 insertions(+), 39 deletions(-) (limited to 'lib/urlfilter') 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(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(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(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(parsedLine, UrlFilter::StringStartsWith); - } else if(parsedLine.endsWith(QLatin1Literal("|"))) { + } else if(parsedLine.endsWith(QLatin1String("|"))) { // string ends with rule parsedLine.chop(1); r.matcher = new ContentsMatcher(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(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> parseComment(QString &line) std::optional> 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 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); } diff --git a/lib/urlfilter/hostlist/hostlist.cpp b/lib/urlfilter/hostlist/hostlist.cpp index ff652cf..bec79ea 100644 --- a/lib/urlfilter/hostlist/hostlist.cpp +++ b/lib/urlfilter/hostlist/hostlist.cpp @@ -52,18 +52,18 @@ std::pair HostList::match(const QUrl& firstPart void HostList::parseLine(const QString& line) { // check comment - if(line.startsWith(QLatin1Literal("#"))) + if(line.startsWith(QLatin1String("#"))) return; QString parsedLine = line.trimmed(); // malformed rule - if(!parsedLine.contains(QLatin1Literal(" "))) + if(!parsedLine.contains(QLatin1String(" "))) return; - const QStringList parts = parsedLine.split(QLatin1Literal(" ")); + const QStringList parts = parsedLine.split(QLatin1String(" ")); const QString &redirect = parts.at(0); - const auto action = (redirect == QLatin1Literal("0.0.0.0")) ? UrlFilter::Block : UrlFilter::Redirect; + const auto action = (redirect == QLatin1String("0.0.0.0")) ? UrlFilter::Block : UrlFilter::Redirect; for(int i = 1; i < parts.size(); i++) { const QString &domain = parts.at(i); -- cgit v1.2.1