-
Notifications
You must be signed in to change notification settings - Fork 0
/
regexprule.h
80 lines (67 loc) · 2.45 KB
/
regexprule.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
** regexprule.h
**
** Copyright © Quazaa Development Team, 2009-2013.
** This file is part of the Quazaa Security Library (quazaa.sourceforge.net)
**
** The Quazaa Security Library is free software; this file may be used under the terms of the GNU
** General Public License version 3.0 or later as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** The Quazaa Security Library 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.
**
** Please review the following information to ensure the GNU General Public
** License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** You should have received a copy of the GNU General Public License version
** 3.0 along with the Quazaa Security Library; if not, write to the Free Software Foundation,
** Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef REGEXPRULE_H
#define REGEXPRULE_H
#include "securerule.h"
#if QT_VERSION >= 0x050000
# include <QRegularExpression>
#else
# include <QRegExp>
#endif
namespace Security
{
/**
* @brief The RegularExpressionRule class manages matching query hits (respectively their file
* names) against regular expressions. Note that this rule supports so-called special elements,
* which insert the query keywords into the rule regex.
*
* The supported special elements are:
* * <_> Inserts all query keywords.
* * <0>..<9> Inserts query keyword number 0..9
* * <> Inserts the next query keyword
*/
class RegularExpressionRule : public Rule
{
private:
// There are two kinds of rules:
// 1. Those which contain <_>, <1>...<9> or <> (e.g. special elements)
// 2. All other rules.
bool m_bSpecialElements; // true if the rule contains special elements
#if QT_VERSION >= 0x050000
QRegularExpression m_regularExpressionContent;
#else
QRegExp m_regExpContent;
#endif
public:
RegularExpressionRule();
Rule* getCopy() const;
bool operator==( const Rule& pRule ) const;
bool parseContent( const QString& sContent );
bool match( const QList<QString>& lQuery, const QString& sContent ) const;
void toXML( QXmlStreamWriter& oXMLdocument ) const;
private:
static bool replace( QString& sReplace, const QList<QString>& lQuery, quint8& nCurrent );
};
}
#endif // REGEXPRULE_H