You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tdelibs/tdecore/tdestringmatcher.h

130 lines
3.0 KiB
C++

#ifndef TDESTRINGMATCHER_H
#define TDESTRINGMATCHER_H
#include "tdelibs_export.h"
#include <tqobject.h>
#include <tqvaluevector.h>
#define TSMTRACE kdWarning() << "<TSMTRACE> "
/**
* Enumeration used by the TDEStringMatcher class
* defining types of patterns to be matched
*/
enum class PatternType: uchar
{
REGEX = 0,
WILDCARD = 1,
//EXTGLOB = 2, // RESERVED
SUBSTRING = 2,
DEFAULT = REGEX
};
/**
* Enumeration used by the TDEStringMatcher class
* defining special handling of alphanumeric characters
*/
enum class ANCHandling: uchar
{
CASE_SENSITIVE = 0, // No handling
CASE_INSENSITIVE = 1, // Alphabetic case variants are same
EQUIVALENCE = 2, // Alphanumeric equivalents are same
DEFAULT = CASE_SENSITIVE
};
/**
* Structure used by the TDEStringMatcher class
* representing properties of a single match specification.
*/
struct MatchSpec
{
PatternType patternType;
ANCHandling ancHandling;
bool wantMatch; // "matching" vs. "not matching"
TQString pattern;
};
/**
* Container used in a TDEStringMatcher object
* representing multiple match specifications.
*/
typedef TQValueVector<MatchSpec> MatchSpecList;
/**
*
* Generic string matcher class.
*/
class TDECORE_EXPORT TDEStringMatcher : public TQObject
{
Q_OBJECT
public:
TDEStringMatcher();
~TDEStringMatcher();
/**
@return list of currently defined match specifications.
*/
MatchSpecList getMatchSpecs();
/**
@return string encoding list of currently defined match specifications.
*/
TQString getMatchSpecString();
/**
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 );
/**
@return whether or not @param stringToMatch matches all of
the current match specifications.
*/
bool matchAll( const TQString& stringToMatch );
/**
Utility function for converting a wildcard pattern string
to a regular expression pattern string.
*/
TQString wildcardToRegex( const TQString& wildcardPattern );
/**
Utility function for escaping all regex-specific characters.
*/
TQString escapeRegexChars( const TQString& basicString );
signals:
void patternsChanged();
private:
class TDEStringMatcherPrivate;
TDEStringMatcherPrivate *p;
};
// Use vertical tab as m_patternString separator
inline constexpr char SEP { 0x0B };
#endif