fix logic
[personal-kdelibs.git] / khtml / khtml_filter_p.h
blob0ef67656331ff318114bec27322568f6b7600e37
1 /* This file is part of the KDE project
3 Copyright (C) 2005 Ivor Hewitt <ivor@kde.org>
4 Copyright (C) 2008 Maksim Orlovich <maksim@kde.org>
5 Copyright (C) 2008 Vyacheslav Tokarev <tsjoker@gmail.com>
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
23 #include <QString>
24 #include <QRegExp>
25 #include <QVector>
26 #include <wtf/HashMap.h>
27 #include <QHash>
28 #include <QBitArray>
30 namespace khtml {
32 // Updateable Multi-String Matcher based on Rabin-Karp's algorithm
33 class StringsMatcher {
34 public:
35 // add filter to matching set
36 void addString(const QString& pattern);
38 // check if string match at least one string from matching set
39 bool isMatched(const QString& str) const;
41 // add filter to matching set with wildcards (*,?) in it
42 void addWildedString(const QString& prefix, const QRegExp& rx);
44 void clear();
46 private:
47 QVector<QString> stringFilters;
48 QVector<QString> shortStringFilters;
49 QVector<QRegExp> reFilters;
50 QVector<QString> rePrefixes;
51 QBitArray fastLookUp;
53 WTF::HashMap<int, QVector<int> > stringFiltersHash;
56 // This represents a set of filters that may match URLs.
57 // Currently it supports a subset of AddBlock Plus functionality.
58 class FilterSet {
59 public:
60 // Parses and registers a filter. This will also strip @@ for exclusion rules, skip comments, etc.
61 // The user does have to split black and white lists into separate sets, however
62 void addFilter(const QString& filter);
64 bool isUrlMatched(const QString& url);
66 void clear();
68 private:
69 QVector<QRegExp> reFilters;
70 StringsMatcher stringFiltersMatcher;
75 // kate: indent-width 4; replace-tabs on; tab-width 4; space-indent on;