X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fexpressionmatch.h;h=60161f782b57e5005f87543d69552d0afa45ca75;hp=0f5acfcfb3f1b5cadc8c330293e1924608c898ae;hb=579e559a6322209df7cd51c34801fecff5fe734b;hpb=09906ed00eb2ba2fa1cc0f5464f166e5a85a2c92 diff --git a/src/common/expressionmatch.h b/src/common/expressionmatch.h index 0f5acfcf..60161f78 100644 --- a/src/common/expressionmatch.h +++ b/src/common/expressionmatch.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2019 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,39 +20,32 @@ #pragma once -#include -#include +#include "common-export.h" -#if QT_VERSION >= 0x050000 #include -#else -#include -#endif +#include +#include /** * Expression matcher with multiple modes of operation and automatic caching for performance */ -class ExpressionMatch +class COMMON_EXPORT ExpressionMatch { - public: /// Expression matching mode -#if QT_VERSION >= 0x050000 - enum class MatchMode { -#else - enum MatchMode { -#endif - MatchPhrase, ///< Match phrase as specified, no special handling - MatchMultiPhrase, ///< Match phrase as specified, split on \n only - MatchWildcard, ///< Match wildcards, "!" at start inverts, "\" escapes - MatchMultiWildcard, ///< Match wildcards, split ; or \n, "!" at start inverts, "\" escapes - MatchRegEx ///< Match as regular expression, "!..." invert regex, "\" escapes + enum class MatchMode + { + MatchPhrase, ///< Match phrase as specified, no special handling + MatchMultiPhrase, ///< Match phrase as specified, split on \n only + MatchWildcard, ///< Match wildcards, "!" at start inverts, "\" escapes + MatchMultiWildcard, ///< Match wildcards, split ; or \n, "!" at start inverts, "\" escapes + MatchRegEx ///< Match as regular expression, "!..." invert regex, "\" escapes }; /** * Construct an empty ExpressionMatch */ - ExpressionMatch() {} + ExpressionMatch() = default; /** * Construct an Expression match with the given parameters @@ -65,7 +58,7 @@ public: * @endparblock * @param caseSensitive If true, match case-sensitively, otherwise ignore case when matching */ - ExpressionMatch(const QString &expression, MatchMode mode, bool caseSensitive); + ExpressionMatch(const QString& expression, MatchMode mode, bool caseSensitive); /** * Check if the given string matches the stored expression @@ -74,7 +67,7 @@ public: * @param matchEmpty If true, always match when the expression is empty, otherwise never match * @return True if match found, otherwise false */ - bool match(const QString &string, bool matchEmpty = false) const; + bool match(const QString& string, bool matchEmpty = false) const; /** * Gets if the source expression is empty @@ -88,10 +81,10 @@ public: * * @return True if given expression is valid, otherwise false */ - inline bool isValid() const { + inline bool isValid() const + { // Either this must be empty, or normal or inverted rules must be valid and active - return (_sourceExpressionEmpty - || (_matchRegExActive && _matchRegEx.isValid()) + return (_sourceExpressionEmpty || (_matchRegExActive && _matchRegEx.isValid()) || (_matchInvertRegExActive && _matchInvertRegEx.isValid())); } @@ -107,7 +100,8 @@ public: * * @param expression A phrase, wildcard expression, or regular expression */ - void setSourceExpression(const QString &expression) { + void setSourceExpression(const QString& expression) + { if (_sourceExpression != expression) { _sourceExpression = expression; cacheRegEx(); @@ -130,7 +124,8 @@ public: * @see ExpressionMatch::MatchMode * @endparblock */ - void setSourceMode(MatchMode mode) { + void setSourceMode(MatchMode mode) + { if (_sourceMode != mode) { _sourceMode = mode; cacheRegEx(); @@ -149,18 +144,18 @@ public: * * @param caseSensitive If true, match case-sensitively, otherwise ignore case when matching */ - void setSourceCaseSensitive(bool caseSensitive) { + void setSourceCaseSensitive(bool caseSensitive) + { if (_sourceCaseSensitive != caseSensitive) { _sourceCaseSensitive = caseSensitive; cacheRegEx(); } } - bool operator!=(const ExpressionMatch &other) const + bool operator!=(const ExpressionMatch& other) const { - return (_sourceExpression != other._sourceExpression || - _sourceMode != other._sourceMode || - _sourceCaseSensitive != other._sourceCaseSensitive); + return (_sourceExpression != other._sourceExpression || _sourceMode != other._sourceMode + || _sourceCaseSensitive != other._sourceCaseSensitive); } /** @@ -174,7 +169,7 @@ public: * @param originalRule MultiWildcard rule list, ";"-separated * @return Trimmed MultiWildcard rule list */ - static QString trimMultiWildcardWhitespace(const QString &originalRule); + static QString trimMultiWildcardWhitespace(const QString& originalRule); private: /** @@ -189,13 +184,9 @@ private: * * @param regExString Regular expression string * @param caseSensitive If true, match case-sensitively, otherwise ignore case when matching - * @return Configured QRegExp class on Qt 4, QRegularExpression on Qt 5 + * @return Configured QRegularExpression */ -#if QT_VERSION >= 0x050000 - static QRegularExpression regExFactory(const QString ®ExString, bool caseSensitive); -#else - static QRegExp regExFactory(const QString ®ExString, bool caseSensitive); -#endif + static QRegularExpression regExFactory(const QString& regExString, bool caseSensitive); /** * Escapes any regular expression characters in a string so they have no special meaning @@ -203,7 +194,7 @@ private: * @param phrase String containing potential regular expression special characters * @return QString with all regular expression characters escaped */ - static QString regExEscape(const QString &phrase); + static QString regExEscape(const QString& phrase); /** * Converts a multiple-phrase rule into a regular expression @@ -213,7 +204,7 @@ private: * @param originalRule MultiPhrase rule list, "\n"-separated * @return A regular expression matching the given phrases */ - static QString convertFromMultiPhrase(const QString &originalRule); + static QString convertFromMultiPhrase(const QString& originalRule); /** * Internally converts a wildcard rule into regular expressions @@ -223,7 +214,7 @@ private: * @param originalRule MultiWildcard rule list, ";"-separated * @param caseSensitive If true, match case-sensitively, otherwise ignore case when matching */ - void generateFromMultiWildcard(const QString &originalRule, bool caseSensitive); + void generateFromMultiWildcard(const QString& originalRule, bool caseSensitive); /** * Converts a wildcard expression into a regular expression @@ -233,7 +224,7 @@ private: * @see ExpressionMatch::convertFromWildcard() * @return QString with all regular expression characters escaped */ - static QString wildcardToRegEx(const QString &expression); + static QString wildcardToRegEx(const QString& expression); // Original/source components QString _sourceExpression = {}; ///< Expression match string given on creation @@ -241,21 +232,13 @@ private: bool _sourceCaseSensitive = false; ///< Expression case sensitive on creation // Derived components - bool _sourceExpressionEmpty = false; ///< Cached expression match string is empty + bool _sourceExpressionEmpty = false; ///< Cached expression match string is empty /// Underlying regular expression matching instance for normal (noninverted) rules -#if QT_VERSION >= 0x050000 QRegularExpression _matchRegEx = {}; -#else - QRegExp _matchRegEx = {}; -#endif - bool _matchRegExActive = false; ///< If true, use normal expression in matching + bool _matchRegExActive = false; ///< If true, use normal expression in matching /// Underlying regular expression matching instance for inverted rules -#if QT_VERSION >= 0x050000 QRegularExpression _matchInvertRegEx = {}; -#else - QRegExp _matchInvertRegEx = {}; -#endif - bool _matchInvertRegExActive = false; ///< If true, use invert expression in matching + bool _matchInvertRegExActive = false; ///< If true, use invert expression in matching };