X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fexpressionmatch.h;fp=src%2Fcommon%2Fexpressionmatch.h;h=daaa6e8cde7150d593bc17007b4ca2b6917d8d0b;hp=689d14f9de65fc757812c193a2a1270eef4ed6cd;hb=c1cf157116de7fc3da96203aa6f03c38c7ebb650;hpb=30b159cb876a9495de42e9a3e70ca050516f0805 diff --git a/src/common/expressionmatch.h b/src/common/expressionmatch.h index 689d14f9..daaa6e8c 100644 --- a/src/common/expressionmatch.h +++ b/src/common/expressionmatch.h @@ -31,15 +31,15 @@ */ class COMMON_EXPORT ExpressionMatch { - public: /// Expression matching mode - 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 + 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 }; /** @@ -58,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 @@ -67,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 @@ -81,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())); } @@ -100,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(); @@ -123,7 +124,8 @@ public: * @see ExpressionMatch::MatchMode * @endparblock */ - void setSourceMode(MatchMode mode) { + void setSourceMode(MatchMode mode) + { if (_sourceMode != mode) { _sourceMode = mode; cacheRegEx(); @@ -142,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); } /** @@ -167,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: /** @@ -184,7 +186,7 @@ private: * @param caseSensitive If true, match case-sensitively, otherwise ignore case when matching * @return Configured QRegularExpression */ - static QRegularExpression regExFactory(const QString ®ExString, bool caseSensitive); + static QRegularExpression regExFactory(const QString& regExString, bool caseSensitive); /** * Escapes any regular expression characters in a string so they have no special meaning @@ -192,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 @@ -202,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 @@ -212,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 @@ -222,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 @@ -230,13 +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 QRegularExpression _matchRegEx = {}; - 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 QRegularExpression _matchInvertRegEx = {}; - bool _matchInvertRegExActive = false; ///< If true, use invert expression in matching + bool _matchInvertRegExActive = false; ///< If true, use invert expression in matching };