CachedRegexMatcher.h 686 B

123456789101112131415161718192021222324252627282930
  1. //
  2. // Created by Tobias Hieta on 20/08/15.
  3. //
  4. #ifndef KONVERGO_CACHEDREGEXMATCHER_H
  5. #define KONVERGO_CACHEDREGEXMATCHER_H
  6. #include <QRegExp>
  7. #include <QVariant>
  8. #include <QString>
  9. #include <QHash>
  10. typedef QPair<QRegExp, QVariant> MatcherValuePair;
  11. typedef QList<MatcherValuePair> MatcherValueList;
  12. class CachedRegexMatcher : public QObject
  13. {
  14. public:
  15. explicit CachedRegexMatcher(QObject* parent = nullptr) : QObject(parent) {}
  16. bool addMatcher(const QString& pattern, const QVariant& result);
  17. QVariant match(const QString& input);
  18. void clear();
  19. private:
  20. MatcherValueList m_matcherList;
  21. QHash<QString, QVariant> m_matcherCache;
  22. };
  23. #endif //KONVERGO_CACHEDREGEXMATCHER_H