summaryrefslogtreecommitdiffstats
path: root/tdecore/tdestringmatcher.h
diff options
context:
space:
mode:
Diffstat (limited to 'tdecore/tdestringmatcher.h')
-rw-r--r--tdecore/tdestringmatcher.h134
1 files changed, 134 insertions, 0 deletions
diff --git a/tdecore/tdestringmatcher.h b/tdecore/tdestringmatcher.h
new file mode 100644
index 000000000..504ccfa8c
--- /dev/null
+++ b/tdecore/tdestringmatcher.h
@@ -0,0 +1,134 @@
+#ifndef TDESTRINGMATCHER_H
+#define TDESTRINGMATCHER_H
+
+#include "tdelibs_export.h"
+
+#include <tqobject.h>
+#include <tqvaluevector.h>
+
+#define TSMTRACE kdWarning() << "<TSMTRACE> "
+
+namespace TSM
+{
+/**
+ * Enumeration used by the TDEStringMatcher class
+ * defining types of patterns to be matched
+ */
+enum class PatternType: uchar
+{
+ REGEX,
+ WILDCARD,
+ SUBSTRING,
+ //OTHER,
+ DEFAULT = REGEX
+};
+
+/**
+ * Enumeration used by the TDEStringMatcher class
+ * 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 used by the TDEStringMatcher class
+ * representing properties of a single match specification.
+ */
+struct MatchSpec
+{
+ PatternType patternType;
+ ANCHandling ancHandling;
+ bool expectMatch; // "matching" vs. "not matching"
+ TQString pattern;
+};
+
+/**
+ * Container used in a TDEStringMatcher object
+ * representing multiple match specifications.
+ */
+typedef TQValueVector<MatchSpec> MatchSpecList;
+
+// Use horizontal tab as m_patternString separator
+inline constexpr char PatterStringDivider { '\t' };
+
+} // End of namespace TSM
+
+
+/**
+ * Generic string matcher class.
+ */
+class TDECORE_EXPORT TDEStringMatcher : public TQObject
+{
+Q_OBJECT
+public:
+
+ TDEStringMatcher();
+ ~TDEStringMatcher();
+
+ /**
+ @return list of currently defined match specifications.
+ */
+ const TSM::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( TSM::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;
+
+ /**
+ @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