From c896cc340d7e6e0878b3249c5792e6d88a12cf42 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 30 Apr 2010 11:23:37 +0200 Subject: A coding style round --- src/adblock/adblockrule.cpp | 72 ++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 36 deletions(-) (limited to 'src/adblock/adblockrule.cpp') diff --git a/src/adblock/adblockrule.cpp b/src/adblock/adblockrule.cpp index c0c3fd5b..d11cc026 100644 --- a/src/adblock/adblockrule.cpp +++ b/src/adblock/adblockrule.cpp @@ -38,9 +38,9 @@ * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved - * by the membership of KDE e.V.), which shall act as a proxy + * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -67,34 +67,34 @@ AdBlockRule::AdBlockRule(const QString &filter) - : m_optionMatchRule(false) + : m_optionMatchRule(false) { bool isRegExpRule = false; QString parsedLine = filter; - - if ( parsedLine.startsWith( QL1C('/') ) && parsedLine.endsWith( QL1C('/') ) ) + + if (parsedLine.startsWith(QL1C('/')) && parsedLine.endsWith(QL1C('/'))) { parsedLine = parsedLine.mid(1); parsedLine = parsedLine.left(parsedLine.size() - 1); isRegExpRule = true; } - - int optionsNumber = parsedLine.indexOf( QL1C('$'), 0); + + int optionsNumber = parsedLine.indexOf(QL1C('$'), 0); QStringList options; - - if (optionsNumber >= 0) + + if (optionsNumber >= 0) { options = parsedLine.mid(optionsNumber + 1).split(QL1C(',')); parsedLine = parsedLine.left(optionsNumber); } - if(!isRegExpRule) + if (!isRegExpRule) parsedLine = convertPatternToRegExp(parsedLine); - + m_regExp = QRegExp(parsedLine, Qt::CaseInsensitive, QRegExp::RegExp2); - if ( options.contains( QL1S("match-case") )) + if (options.contains(QL1S("match-case"))) { m_regExp.setCaseSensitivity(Qt::CaseSensitive); m_optionMatchRule = true; @@ -111,19 +111,19 @@ bool AdBlockRule::match(const QString &encodedUrl) const // TODO: Reimplement this in rekonq 0.5 :) // -// if (matched && !m_options.isEmpty()) +// if (matched && !m_options.isEmpty()) // { // // we only support domain right now // if (m_options.count() == 1) // { -// foreach (const QString &option, m_options) +// foreach (const QString &option, m_options) // { -// if (option.startsWith( QL1S("domain=") )) +// if (option.startsWith( QL1S("domain=") )) // { // QUrl url = QUrl::fromEncoded(encodedUrl.toUtf8()); // QString host = url.host(); // QStringList domainOptions = option.mid(7).split( QL1C('|') ); -// foreach (QString domainOption, domainOptions) +// foreach (QString domainOption, domainOptions) // { // bool negate = domainOption.at(0) == QL1C('~'); // if (negate) @@ -147,36 +147,36 @@ bool AdBlockRule::match(const QString &encodedUrl) const QString AdBlockRule::convertPatternToRegExp(const QString &wildcardPattern) { QString pattern = wildcardPattern; - + // remove multiple wildcards - pattern.replace(QRegExp( QL1S("\\*+") ), QL1S("*") ); - + pattern.replace(QRegExp(QL1S("\\*+")), QL1S("*")); + // remove anchors following separator placeholder - pattern.replace(QRegExp( QL1S("\\^\\|$") ), QL1S("^") ); - + pattern.replace(QRegExp(QL1S("\\^\\|$")), QL1S("^")); + // remove leading wildcards - pattern.replace(QRegExp( QL1S("^(\\*)") ), QL1S("") ); - + pattern.replace(QRegExp(QL1S("^(\\*)")), QL1S("")); + // remove trailing wildcards - pattern.replace(QRegExp( QL1S("(\\*)$") ), QL1S("") ); - + pattern.replace(QRegExp(QL1S("(\\*)$")), QL1S("")); + // escape special symbols - pattern.replace(QRegExp( QL1S("(\\W)") ), QL1S("\\\\1") ); - + pattern.replace(QRegExp(QL1S("(\\W)")), QL1S("\\\\1")); + // process extended anchor at expression start - pattern.replace(QRegExp( QL1S("^\\\\\\|\\\\\\|") ), QL1S("^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?") ); - + pattern.replace(QRegExp(QL1S("^\\\\\\|\\\\\\|")), QL1S("^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?")); + // process separator placeholders - pattern.replace(QRegExp( QL1S("\\\\\\^") ), QL1S("(?:[^\\w\\d\\-.%]|$)") ); - + pattern.replace(QRegExp(QL1S("\\\\\\^")), QL1S("(?:[^\\w\\d\\-.%]|$)")); + // process anchor at expression start - pattern.replace(QRegExp( QL1S("^\\\\\\|") ), QL1S("^") ); - + pattern.replace(QRegExp(QL1S("^\\\\\\|")), QL1S("^")); + // process anchor at expression end - pattern.replace(QRegExp( QL1S("\\\\\\|$") ), QL1S("$") ); - + pattern.replace(QRegExp(QL1S("\\\\\\|$")), QL1S("$")); + // replace wildcards by .* - pattern.replace(QRegExp( QL1S("\\\\\\*") ), QL1S(".*") ); + pattern.replace(QRegExp(QL1S("\\\\\\*")), QL1S(".*")); // Finally, return... return pattern; -- cgit v1.2.1