• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

messageviewer

  • sources
  • kde-4.14
  • kdepim
  • messageviewer
  • adblock
adblockruletextmatchimpl.cpp
Go to the documentation of this file.
1 /* ============================================================
2 *
3 * This file is a part of the rekonq project
4 * Copyright (c) 2013-2015 Montel Laurent <montel@kde.org>
5 * based on code from rekonq
6 * Copyright (C) 2010-2011 by Benjamin Poulain <ikipou at gmail dot com>
7 * Copyright (C) 2010-2013 by Andrea Diamantini <adjam7 at gmail dot com>
8 *
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License or (at your option) version 3 or any later version
14 * accepted by the membership of KDE e.V. (or its successor approved
15 * by the membership of KDE e.V.), which shall act as a proxy
16 * defined in Section 14 of version 3 of the license.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 *
26 * ============================================================ */
27 
28 
29 // Self Includes
30 #include "adblockruletextmatchimpl.h"
31 
32 // Qt Includes
33 #include <QNetworkRequest>
34 
35 using namespace MessageViewer;
36 AdBlockRuleTextMatchImpl::AdBlockRuleTextMatchImpl(const QString &filter)
37  : AdBlockRuleImpl(filter)
38 {
39  Q_ASSERT(AdBlockRuleTextMatchImpl::isTextMatchFilter(filter));
40 
41  m_textToMatch = filter.toLower();
42  m_textToMatch.remove(QLatin1Char('*'));
43 }
44 
45 
46 bool AdBlockRuleTextMatchImpl::match(const QNetworkRequest &request, const QString &encodedUrl, const QString &encodedUrlLowerCase) const
47 {
48  Q_UNUSED(request);
49  Q_UNUSED(encodedUrl);
50  if (m_textToMatch.isEmpty())
51  return false;
52 
53  // Case sensitive compare is faster, but would be incorrect with encodedUrl since
54  // we do want case insensitive.
55  // What we do is work on a lowercase version of m_textToMatch, and compare to the lowercase
56  // version of encodedUrl.
57  return encodedUrlLowerCase.contains(m_textToMatch, Qt::CaseSensitive);
58 }
59 
60 
61 bool AdBlockRuleTextMatchImpl::isTextMatchFilter(const QString &filter)
62 {
63  // We don't deal with options just yet
64  if (filter.contains(QLatin1Char('$')))
65  return false;
66 
67  // We don't deal with element matching
68  if (filter.contains(QLatin1String("##")))
69  return false;
70 
71  // We don't deal with the begin-end matching
72  if (filter.startsWith(QLatin1Char('|')) || filter.endsWith(QLatin1Char('|')))
73  return false;
74 
75  // We only handle * at the beginning or the end
76  int starPosition = filter.indexOf(QLatin1Char('*'));
77  while (starPosition >= 0)
78  {
79  if (starPosition != 0 && starPosition != (filter.length() - 1))
80  return false;
81  starPosition = filter.indexOf(QLatin1Char('*'), starPosition + 1);
82  }
83  return true;
84 }
85 
86 
87 QString AdBlockRuleTextMatchImpl::ruleString() const
88 {
89  return m_textToMatch;
90 }
91 
92 
93 QString AdBlockRuleTextMatchImpl::ruleType() const
94 {
95  return QLatin1String("AdBlockRuleTextMatchImpl");
96 }
QString::indexOf
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
AdBlockRuleImpl
Definition: adblockruleimpl.h:32
MessageViewer::AdBlockRuleTextMatchImpl::ruleType
QString ruleType() const
Definition: adblockruletextmatchimpl.cpp:93
QString::remove
QString & remove(int position, int n)
QNetworkRequest
MessageViewer::AdBlockRuleTextMatchImpl::ruleString
QString ruleString() const
Definition: adblockruletextmatchimpl.cpp:87
MessageViewer::AdBlockRuleTextMatchImpl::match
bool match(const QNetworkRequest &request, const QString &encodedUrl, const QString &encodedUrlLowerCase) const
Definition: adblockruletextmatchimpl.cpp:46
QString::isEmpty
bool isEmpty() const
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
MessageViewer::AdBlockRuleTextMatchImpl::AdBlockRuleTextMatchImpl
AdBlockRuleTextMatchImpl(const QString &filter)
Definition: adblockruletextmatchimpl.cpp:36
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
QString
QString::toLower
QString toLower() const
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
QLatin1Char
QLatin1String
QString::length
int length() const
adblockruletextmatchimpl.h
MessageViewer::AdBlockRuleTextMatchImpl::isTextMatchFilter
static bool isTextMatchFilter(const QString &filter)
Definition: adblockruletextmatchimpl.cpp:61
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:45 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messageviewer

Skip menu "messageviewer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal