From 3533e0d4cce3e7af2df8e6c42f462315da8c9df8 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 2 Jun 2018 11:02:42 +0200 Subject: Clazy fixes --- src/webengine/urlinterceptor.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'src/webengine/urlinterceptor.cpp') diff --git a/src/webengine/urlinterceptor.cpp b/src/webengine/urlinterceptor.cpp index e88e5b7..5e17e78 100644 --- a/src/webengine/urlinterceptor.cpp +++ b/src/webengine/urlinterceptor.cpp @@ -25,13 +25,7 @@ UrlRequestInterceptor::UrlRequestInterceptor(const QString &path, QObject *paren #endif rulesLock.lock(); - for(const auto &k : r.keys()) { - if(rules.contains(k)) { - // - } else { - rules.insert(k, r.value(k)); - } - } + rules.unite(r); rulesLock.unlock(); }); } @@ -57,28 +51,41 @@ QHash parse(const QString &filename) // with a QTextStream we can read lines without getting linebreaks at the end QTextStream hostfile_stream(&hostfile); + while(!hostfile_stream.atEnd()) { + // read line and remove any whitespace at the end const QString &line = hostfile_stream.readLine().trimmed(); // skip comments and empty lines + if(line.isEmpty() || line.startsWith('#')) + continue; + // everything else should be a rule // format is // 0.0.0.0 hostname const QStringList &parts = line.split(' '); const QString &redirect = parts.at(0); - for(const QString &host : parts.mid(1)) { - if(!rules.contains(host)) { + for(auto i = parts.constBegin() + 1; i != parts.constEnd(); ++i) { + if(!rules.contains(*i)) { UrlRequestInterceptor::HostRule rule{}; - rule.isBlocking = redirect == "0.0.0.0"; - rules.insert(host, rule); + rule.isBlocking = (redirect == "0.0.0.0"); + rules.insert(*i, rule); } } + +// for(const QString &host : parts.mid(1)) { +// if(!rules.contains(host)) { +// UrlRequestInterceptor::HostRule rule{}; +// rule.isBlocking = redirect == "0.0.0.0"; +// rules.insert(host, rule); +// } +// } } hostfile.close(); } return rules; -}; \ No newline at end of file +}; -- cgit v1.2.1