common: Disable enum type stream operators for Qt >= 5.14
[quassel.git] / src / common / expressionmatch.h
index 0f5acfc..60161f7 100644 (file)
@@ -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  *
 
 #pragma once
 
-#include <QString>
-#include <QStringList>
+#include "common-export.h"
 
-#if QT_VERSION >= 0x050000
 #include <QRegularExpression>
-#else
-#include <QRegExp>
-#endif
+#include <QString>
+#include <QStringList>
 
 /**
  * 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 QStringexpression, 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 QStringstring, 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 ExpressionMatchother) 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 QStringoriginalRule);
 
 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 &regExString, bool caseSensitive);
-#else
-    static QRegExp regExFactory(const QString &regExString, 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 QStringphrase);
 
     /**
      * 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 QStringoriginalRule);
 
     /**
      * 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 QStringoriginalRule, 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 QStringexpression);
 
     // 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
 };