modernize: Reformat ALL the source... again!
[quassel.git] / src / common / expressionmatch.cpp
index ae5661e..17d08a5 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "logmessage.h"
 
-ExpressionMatch::ExpressionMatch(const QString &expression, MatchMode mode, bool caseSensitive)
+ExpressionMatch::ExpressionMatch(const QStringexpression, MatchMode mode, bool caseSensitive)
 {
     // Store the original parameters for later reference
     _sourceExpression = expression;
@@ -41,8 +41,7 @@ ExpressionMatch::ExpressionMatch(const QString &expression, MatchMode mode, bool
     cacheRegEx();
 }
 
-
-bool ExpressionMatch::match(const QString &string, bool matchEmpty) const
+bool ExpressionMatch::match(const QString& string, bool matchEmpty) const
 {
     // Handle empty expression strings
     if (_sourceExpressionEmpty) {
@@ -77,8 +76,7 @@ bool ExpressionMatch::match(const QString &string, bool matchEmpty) const
     }
 }
 
-
-QString ExpressionMatch::trimMultiWildcardWhitespace(const QString &originalRule)
+QString ExpressionMatch::trimMultiWildcardWhitespace(const QString& originalRule)
 {
     // This gets handled in two steps:
     //
@@ -207,10 +205,9 @@ QString ExpressionMatch::trimMultiWildcardWhitespace(const QString &originalRule
                 break;
             default:
                 // This shouldn't ever happen (even with invalid wildcard rules), log a warning
-                qWarning() << Q_FUNC_INFO << "Wildcard rule"
-                           << rule << "resulted in rule component"
-                           << curString << "with unexpected count of consecutive '\\' ("
-                           << consecutiveSlashes << "), ignoring" << curChar << "character!";
+                qWarning() << Q_FUNC_INFO << "Wildcard rule" << rule << "resulted in rule component" << curString
+                           << "with unexpected count of consecutive '\\' (" << consecutiveSlashes << "), ignoring" << curChar
+                           << "character!";
                 break;
             }
             consecutiveSlashes = 0;
@@ -228,10 +225,9 @@ QString ExpressionMatch::trimMultiWildcardWhitespace(const QString &originalRule
             }
             else if (consecutiveSlashes > 3) {
                 // This shouldn't ever happen (even with invalid wildcard rules), log a warning
-                qWarning() << Q_FUNC_INFO << "Wildcard rule"
-                           << rule << "resulted in rule component"
-                           << curString << "with unexpected count of consecutive '\\' ("
-                           << consecutiveSlashes << "), ignoring" << curChar << "character!";
+                qWarning() << Q_FUNC_INFO << "Wildcard rule" << rule << "resulted in rule component" << curString
+                           << "with unexpected count of consecutive '\\' (" << consecutiveSlashes << "), ignoring" << curChar
+                           << "character!";
                 break;
             }
             break;
@@ -254,10 +250,8 @@ QString ExpressionMatch::trimMultiWildcardWhitespace(const QString &originalRule
                 break;
             default:
                 // This shouldn't ever happen (even with invalid wildcard rules), log a warning
-                qWarning() << Q_FUNC_INFO << "Wildcard rule"
-                           << rule << "resulted in rule component"
-                           << curString << "with unexpected count of consecutive '\\' ("
-                           << consecutiveSlashes << "), applying newline split anyways!";
+                qWarning() << Q_FUNC_INFO << "Wildcard rule" << rule << "resulted in rule component" << curString
+                           << "with unexpected count of consecutive '\\' (" << consecutiveSlashes << "), applying newline split anyways!";
                 break;
             }
 
@@ -288,10 +282,9 @@ QString ExpressionMatch::trimMultiWildcardWhitespace(const QString &originalRule
                 break;
             default:
                 // This shouldn't ever happen (even with invalid wildcard rules), log a warning
-                qWarning() << Q_FUNC_INFO << "Wildcard rule"
-                           << rule << "resulted in rule component"
-                           << curString << "with unexpected count of consecutive '\\' ("
-                           << consecutiveSlashes << "), ignoring " << curChar << "char escape!";
+                qWarning() << Q_FUNC_INFO << "Wildcard rule" << rule << "resulted in rule component" << curString
+                           << "with unexpected count of consecutive '\\' (" << consecutiveSlashes << "), ignoring " << curChar
+                           << "char escape!";
                 break;
             }
             consecutiveSlashes = 0;
@@ -308,7 +301,6 @@ QString ExpressionMatch::trimMultiWildcardWhitespace(const QString &originalRule
     return result.trimmed();
 }
 
-
 void ExpressionMatch::cacheRegEx()
 {
     _matchRegExActive = false;
@@ -326,8 +318,7 @@ void ExpressionMatch::cacheRegEx()
         // Match entire phrase, noninverted
         // Don't trim whitespace for phrase matching as someone might want to match on " word ", a
         // more-specific request than "word".
-        _matchRegEx = regExFactory("(?:^|\\W)" + regExEscape(_sourceExpression) + "(?:\\W|$)",
-                                   _sourceCaseSensitive);
+        _matchRegEx = regExFactory("(?:^|\\W)" + regExEscape(_sourceExpression) + "(?:\\W|$)", _sourceCaseSensitive);
         _matchRegExActive = true;
         break;
     case MatchMode::MatchMultiPhrase:
@@ -342,19 +333,16 @@ void ExpressionMatch::cacheRegEx()
         if (_sourceExpression.startsWith("!")) {
             // Inverted rule: take the remainder of the string
             // "^" + invertComponents.at(0) + "$"
-            _matchInvertRegEx = regExFactory("^" + wildcardToRegEx(_sourceExpression.mid(1)) + "$",
-                                             _sourceCaseSensitive);
+            _matchInvertRegEx = regExFactory("^" + wildcardToRegEx(_sourceExpression.mid(1)) + "$", _sourceCaseSensitive);
             _matchInvertRegExActive = true;
         }
         else {
             // Normal rule: take the whole string
             // Account for any escaped "!" (i.e. "\!") by skipping past the "\", but don't skip past
             // escaped "\" (i.e. "\\!")
-            _matchRegEx =
-                    regExFactory("^" + wildcardToRegEx(_sourceExpression.startsWith("\\!")
-                                                       ? _sourceExpression.mid(1)
-                                                       : _sourceExpression) + "$",
-                                 _sourceCaseSensitive);
+            _matchRegEx = regExFactory("^" + wildcardToRegEx(_sourceExpression.startsWith("\\!") ? _sourceExpression.mid(1) : _sourceExpression)
+                                           + "$",
+                                       _sourceCaseSensitive);
             _matchRegExActive = true;
         }
         break;
@@ -375,10 +363,8 @@ void ExpressionMatch::cacheRegEx()
             // Normal rule: take the whole string
             // Account for any escaped "!" (i.e. "\!") by skipping past the "\", but don't skip past
             // escaped "\" (i.e. "\\!")
-            _matchRegEx =
-                    regExFactory(_sourceExpression.startsWith("\\!") ? _sourceExpression.mid(1)
-                                                                     : _sourceExpression,
-                                 _sourceCaseSensitive);
+            _matchRegEx = regExFactory(_sourceExpression.startsWith("\\!") ? _sourceExpression.mid(1) : _sourceExpression,
+                                       _sourceCaseSensitive);
             _matchRegExActive = true;
         }
         break;
@@ -393,28 +379,24 @@ void ExpressionMatch::cacheRegEx()
         // level as ideally someone's not just going to leave a broken match rule around.  For
         // MatchRegEx, they probably need to fix their regex rule.  For the other modes, there's
         // probably a bug in the parsing routines (which should also be fixed).
-        quInfo() << "Could not parse expression match rule"
-                 << _sourceExpression << "(match mode:" << (int)_sourceMode
+        quInfo() << "Could not parse expression match rule" << _sourceExpression << "(match mode:" << (int)_sourceMode
                  << "), this rule will be ignored";
     }
 }
 
-
-QRegularExpression ExpressionMatch::regExFactory(const QString &regExString,
-                                                 bool caseSensitive)
+QRegularExpression ExpressionMatch::regExFactory(const QString& regExString, bool caseSensitive)
 {
     // Construct the regular expression object, setting case sensitivity as appropriate
-    QRegularExpression newRegEx = QRegularExpression(regExString, caseSensitive ?
-                                                         QRegularExpression::PatternOption::NoPatternOption
-                                                       : QRegularExpression::PatternOption::CaseInsensitiveOption);
+    QRegularExpression newRegEx = QRegularExpression(regExString,
+                                                     caseSensitive ? QRegularExpression::PatternOption::NoPatternOption
+                                                                   : QRegularExpression::PatternOption::CaseInsensitiveOption);
 
     // Check if rule is valid
     if (!newRegEx.isValid()) {
         // This can happen with invalid regex, so make it a bit more user-friendly.  Keep this
         // distinct from the main info-level message for easier debugging in case a regex component
         // in Wildcard or Phrase mode breaks.
-        qDebug() << "Internal regular expression component" << regExString
-                 << "is invalid and will be ignored";
+        qDebug() << "Internal regular expression component" << regExString << "is invalid and will be ignored";
     }
     // Qt offers explicit control over when QRegularExpression objects get optimized.
     // By default, patterns are only optimized after some number of uses as defined
@@ -443,22 +425,20 @@ QRegularExpression ExpressionMatch::regExFactory(const QString &regExString,
     return newRegEx;
 }
 
-
-QString ExpressionMatch::regExEscape(const QString &phrase)
+QString ExpressionMatch::regExEscape(const QString& phrase)
 {
     // Escape the given phrase of any special regular expression characters
     return QRegularExpression::escape(phrase);
 }
 
-
-QString ExpressionMatch::convertFromMultiPhrase(const QString &originalRule)
+QString ExpressionMatch::convertFromMultiPhrase(const QString& originalRule)
 {
     // Convert the multi-phrase rule into regular expression format
     // Split apart the original rule into components
     // Use QStringList instead of std::vector<QString> to make use of Qt's built-in .join() method
     QStringList components = {};
     // Split on "\n"
-    for (auto &&component : originalRule.split("\n", QString::SkipEmptyParts)) {
+    for (auto&& component : originalRule.split("\n", QString::SkipEmptyParts)) {
         // Don't trim whitespace to maintain consistency with single phrase matching
         // As trimming is not performed, empty components will already be skipped.  This means " "
         // is considered a valid matching phrase.
@@ -483,8 +463,7 @@ QString ExpressionMatch::convertFromMultiPhrase(const QString &originalRule)
     }
 }
 
-
-void ExpressionMatch::generateFromMultiWildcard(const QString &originalRule, bool caseSensitive)
+void ExpressionMatch::generateFromMultiWildcard(const QString& originalRule, bool caseSensitive)
 {
     // Convert the wildcard rule into regular expression format
     // First, reset the existing match expressions
@@ -533,7 +512,6 @@ void ExpressionMatch::generateFromMultiWildcard(const QString &originalRule, boo
     // "\\" and "\" are not downconverted to allow for other escape codes to be detected in
     // ExpressionMatch::wildcardToRegex
 
-
     // Example:
     //
     // > Wildcard rule
@@ -679,10 +657,9 @@ void ExpressionMatch::generateFromMultiWildcard(const QString &originalRule, boo
                 break;
             default:
                 // This shouldn't ever happen (even with invalid wildcard rules), log a warning
-                qWarning() << Q_FUNC_INFO << "Wildcard rule"
-                           << rule << "resulted in rule component"
-                           << curString << "with unexpected count of consecutive '\\' ("
-                           << consecutiveSlashes << "), ignoring" << curChar << "character!";
+                qWarning() << Q_FUNC_INFO << "Wildcard rule" << rule << "resulted in rule component" << curString
+                           << "with unexpected count of consecutive '\\' (" << consecutiveSlashes << "), ignoring" << curChar
+                           << "character!";
                 isRuleStart = false;
                 break;
             }
@@ -708,10 +685,9 @@ void ExpressionMatch::generateFromMultiWildcard(const QString &originalRule, boo
                     break;
                 default:
                     // This shouldn't ever happen (even with invalid wildcard rules), log a warning
-                    qWarning() << Q_FUNC_INFO << "Wildcard rule"
-                             << rule << "resulted in rule component"
-                             << curString << "with unexpected count of consecutive '\\' ("
-                             << consecutiveSlashes << "), ignoring" << curChar << "character!";
+                    qWarning() << Q_FUNC_INFO << "Wildcard rule" << rule << "resulted in rule component" << curString
+                               << "with unexpected count of consecutive '\\' (" << consecutiveSlashes << "), ignoring" << curChar
+                               << "character!";
                     break;
                 }
             }
@@ -724,16 +700,15 @@ void ExpressionMatch::generateFromMultiWildcard(const QString &originalRule, boo
                     break;
                 case 1:
                 case 2:
-                     // "\!"  -> Elsewhere: keep as "\!"
-                     // "\\!" -> Elsewhere: keep as "\\!"
+                    // "\!"  -> Elsewhere: keep as "\!"
+                    // "\\!" -> Elsewhere: keep as "\\!"
                     curString.append(QString(R"(\)").repeated(consecutiveSlashes) + "!");
                     break;
                 default:
                     // This shouldn't ever happen (even with invalid wildcard rules), log a warning
-                    qWarning() << Q_FUNC_INFO << "Wildcard rule"
-                               << rule << "resulted in rule component"
-                               << curString << "with unexpected count of consecutive '\\' ("
-                               << consecutiveSlashes << "), ignoring" << curChar << "character!";
+                    qWarning() << Q_FUNC_INFO << "Wildcard rule" << rule << "resulted in rule component" << curString
+                               << "with unexpected count of consecutive '\\' (" << consecutiveSlashes << "), ignoring" << curChar
+                               << "character!";
                     break;
                 }
             }
@@ -755,10 +730,9 @@ void ExpressionMatch::generateFromMultiWildcard(const QString &originalRule, boo
             }
             else if (consecutiveSlashes > 3) {
                 // This shouldn't ever happen (even with invalid wildcard rules), log a warning
-                qWarning() << Q_FUNC_INFO << "Wildcard rule"
-                           << rule << "resulted in rule component"
-                           << curString << "with unexpected count of consecutive '\\' ("
-                           << consecutiveSlashes << "), ignoring" << curChar << "character!";
+                qWarning() << Q_FUNC_INFO << "Wildcard rule" << rule << "resulted in rule component" << curString
+                           << "with unexpected count of consecutive '\\' (" << consecutiveSlashes << "), ignoring" << curChar
+                           << "character!";
                 break;
             }
             // Don't set "isRuleStart" here as "\" is used in escape sequences
@@ -782,10 +756,8 @@ void ExpressionMatch::generateFromMultiWildcard(const QString &originalRule, boo
                 break;
             default:
                 // This shouldn't ever happen (even with invalid wildcard rules), log a warning
-                qWarning() << Q_FUNC_INFO << "Wildcard rule"
-                           << rule << "resulted in rule component"
-                           << curString << "with unexpected count of consecutive '\\' ("
-                           << consecutiveSlashes << "), applying newline split anyways!";
+                qWarning() << Q_FUNC_INFO << "Wildcard rule" << rule << "resulted in rule component" << curString
+                           << "with unexpected count of consecutive '\\' (" << consecutiveSlashes << "), applying newline split anyways!";
                 break;
             }
 
@@ -823,10 +795,9 @@ void ExpressionMatch::generateFromMultiWildcard(const QString &originalRule, boo
                 break;
             default:
                 // This shouldn't ever happen (even with invalid wildcard rules), log a warning
-                qWarning() << Q_FUNC_INFO << "Wildcard rule"
-                           << rule << "resulted in rule component"
-                           << curString << "with unexpected count of consecutive '\\' ("
-                           << consecutiveSlashes << "), ignoring " << curChar << "char escape!";
+                qWarning() << Q_FUNC_INFO << "Wildcard rule" << rule << "resulted in rule component" << curString
+                           << "with unexpected count of consecutive '\\' (" << consecutiveSlashes << "), ignoring " << curChar
+                           << "char escape!";
                 break;
             }
             // Don't mark as past rule start for whitespace (whitespace gets trimmed)
@@ -872,15 +843,13 @@ void ExpressionMatch::generateFromMultiWildcard(const QString &originalRule, boo
             _matchInvertRegEx = regExFactory("^" + invertComponents.at(0) + "$", caseSensitive);
         }
         else {
-            _matchInvertRegEx =
-                    regExFactory("^(?:" + invertComponents.join("|") + ")$", caseSensitive);
+            _matchInvertRegEx = regExFactory("^(?:" + invertComponents.join("|") + ")$", caseSensitive);
         }
         _matchInvertRegExActive = true;
     }
 }
 
-
-QString ExpressionMatch::wildcardToRegEx(const QString &expression)
+QString ExpressionMatch::wildcardToRegEx(const QString& expression)
 {
     // Convert the wildcard expression into regular expression format
 
@@ -993,10 +962,9 @@ QString ExpressionMatch::wildcardToRegEx(const QString &expression)
                 break;
             default:
                 // This shouldn't ever happen (even with invalid wildcard rules), log a warning
-                qWarning() << Q_FUNC_INFO << "Wildcard rule"
-                           << expression << "resulted in escaped regular expression string"
-                           << regExEscaped << " with unexpected count of consecutive '\\' ("
-                           << consecutiveSlashes << "), ignoring" << curChar << "character!";
+                qWarning() << Q_FUNC_INFO << "Wildcard rule" << expression << "resulted in escaped regular expression string"
+                           << regExEscaped << " with unexpected count of consecutive '\\' (" << consecutiveSlashes << "), ignoring"
+                           << curChar << "character!";
                 break;
             }
             consecutiveSlashes = 0;
@@ -1016,10 +984,9 @@ QString ExpressionMatch::wildcardToRegEx(const QString &expression)
                 break;
             default:
                 // This shouldn't ever happen (even with invalid wildcard rules), log a warning
-                qWarning() << Q_FUNC_INFO << "Wildcard rule"
-                           << expression << "resulted in escaped regular expression string"
-                           << regExEscaped << " with unexpected count of consecutive '\\' ("
-                           << consecutiveSlashes << "), ignoring" << curChar << "character!";
+                qWarning() << Q_FUNC_INFO << "Wildcard rule" << expression << "resulted in escaped regular expression string"
+                           << regExEscaped << " with unexpected count of consecutive '\\' (" << consecutiveSlashes << "), ignoring"
+                           << curChar << "character!";
                 break;
             }
             consecutiveSlashes = 0;
@@ -1059,10 +1026,9 @@ QString ExpressionMatch::wildcardToRegEx(const QString &expression)
                 break;
             default:
                 // This shouldn't ever happen (even with invalid wildcard rules), log a warning
-                qWarning() << Q_FUNC_INFO << "Wildcard rule"
-                           << expression << "resulted in escaped regular expression string"
-                           << regExEscaped << " with unexpected count of consecutive '\\' ("
-                           << consecutiveSlashes << "), ignoring" << curChar << "char escape!";
+                qWarning() << Q_FUNC_INFO << "Wildcard rule" << expression << "resulted in escaped regular expression string"
+                           << regExEscaped << " with unexpected count of consecutive '\\' (" << consecutiveSlashes << "), ignoring"
+                           << curChar << "char escape!";
                 break;
             }
             consecutiveSlashes = 0;