From 9d20e99fffeebe67fd8ff27cb4f9e353892f5190 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 25 Feb 2011 00:19:27 +0100 Subject: Coding style --- src/adblock/adblockhostmatcher.cpp | 5 +++-- src/adblock/adblockhostmatcher.h | 5 ++++- src/adblock/adblockmanager.cpp | 10 ++++++---- src/adblock/adblockrule.cpp | 6 +++--- src/adblock/adblockrule.h | 3 ++- src/adblock/adblockrulefallbackimpl.cpp | 26 +++++++++++++++++--------- src/adblock/adblockruleimpl.h | 2 +- src/adblock/adblockrulenullimpl.cpp | 6 +++--- src/adblock/adblockrulenullimpl.h | 2 +- src/adblock/adblockruletextmatchimpl.cpp | 5 +++-- src/adblock/adblockruletextmatchimpl.h | 2 +- 11 files changed, 44 insertions(+), 28 deletions(-) (limited to 'src/adblock') diff --git a/src/adblock/adblockhostmatcher.cpp b/src/adblock/adblockhostmatcher.cpp index c0b25726..021fe12d 100644 --- a/src/adblock/adblockhostmatcher.cpp +++ b/src/adblock/adblockhostmatcher.cpp @@ -31,8 +31,9 @@ bool AdBlockHostMatcher::tryAddFilter(const QString &filter) { - if (filter.startsWith(QL1S("||"))) { - + if (filter.startsWith(QL1S("||"))) + { + QString domain = filter.mid(2); if (!domain.endsWith(QL1C('^'))) diff --git a/src/adblock/adblockhostmatcher.h b/src/adblock/adblockhostmatcher.h index 74b32c3c..bdad883c 100644 --- a/src/adblock/adblockhostmatcher.h +++ b/src/adblock/adblockhostmatcher.h @@ -42,7 +42,10 @@ public: return m_hostList.contains(host.toLower()); } - void clear() { m_hostList.clear(); } + void clear() + { + m_hostList.clear(); + } private: QSet m_hostList; diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index a96475e2..9b096bb9 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -82,7 +82,7 @@ void AdBlockManager::loadSettings(bool checkUpdateDate) // just to be sure.. _isHideAdsEnabled = ReKonfig::hideAdsEnabled(); - + // read settings KSharedConfig::Ptr config = KSharedConfig::openConfig("adblock", KConfig::SimpleConfig, "appdata"); KConfigGroup rulesGroup(config, "rules"); @@ -137,7 +137,7 @@ void AdBlockManager::loadRules(const QStringList &rules) const QString filter = stringRule.mid(2); if (_hostWhiteList.tryAddFilter(filter)) continue; - + AdBlockRule rule(filter); _whiteList << rule; continue; @@ -180,7 +180,8 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa // check white rules before :) - if (_hostWhiteList.match(host)) { + if (_hostWhiteList.match(host)) + { kDebug() << "****ADBLOCK: WHITE RULE (@@) Matched by host matcher: ***********"; kDebug() << "UrlString: " << urlString; return 0; @@ -197,7 +198,8 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa } // then check the black ones :( - if (_hostBlackList.match(host)) { + if (_hostBlackList.match(host)) + { kDebug() << "****ADBLOCK: BLACK RULE Matched by host matcher: ***********"; kDebug() << "UrlString: " << urlString; AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); diff --git a/src/adblock/adblockrule.cpp b/src/adblock/adblockrule.cpp index 3cd50020..87fcb680 100644 --- a/src/adblock/adblockrule.cpp +++ b/src/adblock/adblockrule.cpp @@ -37,7 +37,7 @@ AdBlockRule::AdBlockRule(const QString &filter) { - switch( AdBlockRule::ruleType(filter) ) + switch (AdBlockRule::ruleType(filter)) { case TextRule: m_implementation = QSharedPointer(new AdBlockRuleTextMatchImpl(filter)); @@ -57,10 +57,10 @@ AdBlockRule::AdBlockRule(const QString &filter) RuleTypes AdBlockRule::ruleType(const QString &filter) { - if( AdBlockRuleTextMatchImpl::isTextMatchFilter(filter) ) + if (AdBlockRuleTextMatchImpl::isTextMatchFilter(filter)) return TextRule; - if( AdBlockRuleNullImpl::isNullFilter(filter) ) + if (AdBlockRuleNullImpl::isNullFilter(filter)) return NullRule; return FallbackRule; diff --git a/src/adblock/adblockrule.h b/src/adblock/adblockrule.h index 076c6272..f5f913dc 100644 --- a/src/adblock/adblockrule.h +++ b/src/adblock/adblockrule.h @@ -57,7 +57,8 @@ public: { Q_ASSERT(encodedUrl.toLower() == encodedUrlLowerCase); bool b = m_implementation->match(request, encodedUrl, encodedUrlLowerCase); - if(b) { + if (b) + { kDebug() << m_implementation->ruleType() << ": rule string = " << m_implementation->ruleString(); } return b; diff --git a/src/adblock/adblockrulefallbackimpl.cpp b/src/adblock/adblockrulefallbackimpl.cpp index dfe732df..915516c7 100644 --- a/src/adblock/adblockrulefallbackimpl.cpp +++ b/src/adblock/adblockrulefallbackimpl.cpp @@ -41,7 +41,7 @@ static inline bool isRegExpFilter(const QString &filter) } AdBlockRuleFallbackImpl::AdBlockRuleFallbackImpl(const QString &filter) - : AdBlockRuleImpl(filter) + : AdBlockRuleImpl(filter) { m_regExp.setCaseSensitivity(Qt::CaseInsensitive); m_regExp.setPatternSyntax(QRegExp::RegExp2); @@ -49,19 +49,23 @@ AdBlockRuleFallbackImpl::AdBlockRuleFallbackImpl(const QString &filter) QString parsedLine = filter; const int optionsNumber = parsedLine.lastIndexOf(QL1C('$')); - if (optionsNumber >= 0 && !isRegExpFilter(parsedLine)) { + if (optionsNumber >= 0 && !isRegExpFilter(parsedLine)) + { const QStringList options(parsedLine.mid(optionsNumber + 1).split(QL1C(','))); parsedLine = parsedLine.left(optionsNumber); if (options.contains(QL1S("match-case"))) m_regExp.setCaseSensitivity(Qt::CaseSensitive); - foreach (const QString &option, options) { + foreach(const QString &option, options) + { // Domain restricted filter const QString domainKeyword(QL1S("domain=")); - if (option.startsWith(domainKeyword)) { + if (option.startsWith(domainKeyword)) + { QStringList domainList = option.mid(domainKeyword.length()).split(QL1C('|')); - foreach (const QString &domain, domainList) { + foreach(const QString &domain, domainList) + { if (domain.startsWith(QL1C('~'))) m_whiteDomains.insert(domain.toLower()); else @@ -83,18 +87,22 @@ bool AdBlockRuleFallbackImpl::match(const QNetworkRequest &request, const QStrin { const bool regexpMatch = m_regExp.indexIn(encodedUrl) != -1; - if (regexpMatch && (!m_whiteDomains.isEmpty() || !m_blackDomains.isEmpty())) { + if (regexpMatch && (!m_whiteDomains.isEmpty() || !m_blackDomains.isEmpty())) + { Q_ASSERT(qobject_cast(request.originatingObject())); - const QWebFrame *const origin = static_cast(request.originatingObject()); + const QWebFrame *const origin = static_cast(request.originatingObject()); const QString originDomain = origin->url().host(); - if (!m_whiteDomains.isEmpty()) { + if (!m_whiteDomains.isEmpty()) + { // In this context, white domains means we block anything but what is in the list. if (m_whiteDomains.contains(originDomain)) return false; return true; - } else if (m_blackDomains.contains(originDomain)) { + } + else if (m_blackDomains.contains(originDomain)) + { return true; } return false; diff --git a/src/adblock/adblockruleimpl.h b/src/adblock/adblockruleimpl.h index 2344b698..f1d428d5 100644 --- a/src/adblock/adblockruleimpl.h +++ b/src/adblock/adblockruleimpl.h @@ -35,7 +35,7 @@ public: AdBlockRuleImpl(const QString &) {} virtual ~AdBlockRuleImpl() {} virtual bool match(const QNetworkRequest &request, const QString &encodedUrl, const QString &encodedUrlLowerCase) const = 0; - + // This are added just for debugging purposes virtual QString ruleString() const = 0; virtual QString ruleType() const = 0; diff --git a/src/adblock/adblockrulenullimpl.cpp b/src/adblock/adblockrulenullimpl.cpp index 6d68715d..7f6ab765 100644 --- a/src/adblock/adblockrulenullimpl.cpp +++ b/src/adblock/adblockrulenullimpl.cpp @@ -35,7 +35,7 @@ AdBlockRuleNullImpl::AdBlockRuleNullImpl(const QString &filter) - : AdBlockRuleImpl(filter) + : AdBlockRuleImpl(filter) { } @@ -69,11 +69,11 @@ bool AdBlockRuleNullImpl::isNullFilter(const QString &filter) // background if (option == QL1S("background")) return true; - + // stylesheet if (option == QL1S("stylesheet")) return true; - + // object if (option == QL1S("object")) return true; diff --git a/src/adblock/adblockrulenullimpl.h b/src/adblock/adblockrulenullimpl.h index 3d2e94a1..8a479880 100644 --- a/src/adblock/adblockrulenullimpl.h +++ b/src/adblock/adblockrulenullimpl.h @@ -37,7 +37,7 @@ class AdBlockRuleNullImpl : public AdBlockRuleImpl { - + public: AdBlockRuleNullImpl(const QString &filter); bool match(const QNetworkRequest &, const QString &, const QString &) const; diff --git a/src/adblock/adblockruletextmatchimpl.cpp b/src/adblock/adblockruletextmatchimpl.cpp index 0ca2d40a..d8ec70b6 100644 --- a/src/adblock/adblockruletextmatchimpl.cpp +++ b/src/adblock/adblockruletextmatchimpl.cpp @@ -32,7 +32,7 @@ AdBlockRuleTextMatchImpl::AdBlockRuleTextMatchImpl(const QString &filter) - : AdBlockRuleImpl(filter) + : AdBlockRuleImpl(filter) { Q_ASSERT(AdBlockRuleTextMatchImpl::isTextMatchFilter(filter)); @@ -69,7 +69,8 @@ bool AdBlockRuleTextMatchImpl::isTextMatchFilter(const QString &filter) // We only handle * at the beginning or the end int starPosition = filter.indexOf(QL1C('*')); - while (starPosition >= 0) { + while (starPosition >= 0) + { if (starPosition != 0 && starPosition != (filter.length() - 1)) return false; starPosition = filter.indexOf(QL1C('*'), starPosition + 1); diff --git a/src/adblock/adblockruletextmatchimpl.h b/src/adblock/adblockruletextmatchimpl.h index 3a89c2ba..8600543d 100644 --- a/src/adblock/adblockruletextmatchimpl.h +++ b/src/adblock/adblockruletextmatchimpl.h @@ -41,7 +41,7 @@ public: bool match(const QNetworkRequest &request, const QString &encodedUrl, const QString &encodedUrlLowerCase) const; static bool isTextMatchFilter(const QString &filter); - + QString ruleString() const; QString ruleType() const; -- cgit v1.2.1