You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
3.1 KiB
130 lines
3.1 KiB
#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
|