blob: 24adeb6659ded4c1265ff8b18f6697239c98cedf (
plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
#ifndef TDESTRINGMATCHER_H
#define TDESTRINGMATCHER_H
#include "tdelibs_export.h"
#include <tqobject.h>
#include <tqvaluevector.h>
#define TSMTRACE kdWarning() << "<TSMTRACE> "
// Use horizontal tab as m_patternString separator
inline constexpr char PatternStringDivider = '\t' ;
/**
* Generic string matcher class.
*/
class TDECORE_EXPORT TDEStringMatcher : public TQObject
{
Q_OBJECT
public:
/**
* Enumeration defining types of patterns to be matched
*/
enum class PatternType: uchar
{
REGEX,
WILDCARD,
SUBSTRING,
//OTHER,
DEFAULT = REGEX
};
/**
* Enumeration defining special handling of alphanumeric characters
*/
enum class ANCHandling: uchar
{
CASE_SENSITIVE = 0, // No handling, each character distinct
CASE_INSENSITIVE = 1, // Alphabetic case variants are same
EQUIVALENCE = 2, // Alphanumeric equivalents are same
DEFAULT = CASE_SENSITIVE
};
/**
* Structure representing properties of a single match specification.
*/
struct MatchSpec
{
PatternType patternType;
ANCHandling ancHandling;
bool expectMatch; // "matching" vs. "not matching"
TQString pattern;
};
/**
* Container representing multiple match specifications.
*/
typedef TQValueVector<MatchSpec> MatchSpecList;
TDEStringMatcher();
~TDEStringMatcher();
/**
@return list of currently defined match specifications.
*/
const MatchSpecList getMatchSpecs() const;
/**
@return string encoding list of currently defined match specifications.
*/
const TQString getMatchSpecString() const;
/**
Use @param newMatchSpecList to generate the internal list of match
specifications to be used for pattern matching.
*/
bool setMatchSpecs( MatchSpecList newMatchSpecList );
/**
Use specially encoded @param newPatternString to generate the internal
list of match specifications to be used for pattern matching. Refer
to file README.tdestringmatcher in tdelibs/tdecore source code for
more information on how the input string should be formatted.
*/
bool setMatchSpecs( TQString newMatchSpecString );
/**
@return whether or not @param stringToMatch matches any of
the current match specifications.
*/
bool matchAny( const TQString& stringToMatch ) const;
/**
@return whether or not @param stringToMatch matches all of
the current match specifications.
*/
bool matchAll( const TQString& stringToMatch ) const;
protected:
/**
@return a basic regular expression formed by converting the basic
wildcard expression in @param wildcardPattern.
*/
TQString wildcardToRegex( const TQString& wildcardPattern );
/**
@return a string that is @param basicString with all special regular
expression characters escaped. Useful for regular expression engines
that do not support /Q.../E.
*/
TQString escapeRegexChars( const TQString& basicString );
signals:
void patternsChanged();
private:
class TDEStringMatcherPrivate;
TDEStringMatcherPrivate *d;
};
#endif
|