#ifndef TDESTRINGMATCHER_H #define TDESTRINGMATCHER_H #include "tdelibs_export.h" #include #include #define TSMTRACE kdWarning() << " " // 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 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