modernize: Pass arguments by value and move in constructors
[quassel.git] / src / common / ignorelistmanager.h
index 7bf4bab..bd09608 100644 (file)
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
-#ifndef IGNORELISTMANAGER_H
-#define IGNORELISTMANAGER_H
+#pragma once
+
+#include "common-export.h"
 
-#include <QDebug>
 #include <QString>
 #include <QStringList>
 #include <QRegExp>
+#include <utility>
 
 #include "expressionmatch.h"
 #include "message.h"
 #include "syncableobject.h"
 
-class IgnoreListManager : public SyncableObject
+class COMMON_EXPORT IgnoreListManager : public SyncableObject
 {
+    Q_OBJECT
     SYNCABLE_OBJECT
-        Q_OBJECT
+
 public:
-    inline IgnoreListManager(QObject *parent = 0) : SyncableObject(parent) { setAllowClientUpdates(true); }
+    inline IgnoreListManager(QObject *parent = nullptr) : SyncableObject(parent) { setAllowClientUpdates(true); }
     IgnoreListManager &operator=(const IgnoreListManager &other);
 
     enum IgnoreType {
@@ -59,7 +61,7 @@ public:
     /**
      * Individual ignore list rule
      */
-    class IgnoreListItem {
+    class COMMON_EXPORT IgnoreListItem {
     public:
         /**
          * Construct an empty ignore rule
@@ -80,11 +82,11 @@ public:
          * @param scopeRule        String representing a scope rule expression to match
          * @param isEnabled        True if enabled, otherwise false
          */
-        IgnoreListItem(IgnoreType type, const QString &contents, bool isRegEx,
-                       StrictnessType strictness, ScopeType scope, const QString &scopeRule,
+        IgnoreListItem(IgnoreType type, QString contents, bool isRegEx,
+                       StrictnessType strictness, ScopeType scope, QString scopeRule,
                        bool isEnabled)
-            : _contents(contents), _isRegEx(isRegEx), _strictness(strictness),
-              _scope(scope), _scopeRule(scopeRule), _isEnabled(isEnabled)
+            : _contents(std::move(contents)), _isRegEx(isRegEx), _strictness(strictness),
+              _scope(scope), _scopeRule(std::move(scopeRule)), _isEnabled(isEnabled)
         {
             // Allow passing empty "contents" as they can happen when editing an ignore rule
 
@@ -122,10 +124,27 @@ public:
                 // This is not performance-intensive; sticking with QRegExp for Qt 4 is fine
                 // Split based on whitespace characters
                 QStringList split(contents().split(QRegExp("\\s+"), QString::SkipEmptyParts));
-                // Match on the first item
-                _cacheCtcpSender = split.takeFirst();
-                // Track the rest as CTCP types to ignore
-                _cacheCtcpTypes = split;
+                // Match on the first item, handling empty rules/matches
+                if (!split.isEmpty()) {
+                    // Take the first item as the sender
+                    _cacheCtcpSender = split.takeFirst();
+                    // Track the rest as CTCP types to ignore
+                    _cacheCtcpTypes = split;
+                }
+                else {
+                    // No match found - this can happen if a pure whitespace CTCP ignore rule is
+                    // created.  Fall back to matching all senders.
+                    if (_isRegEx) {
+                        // RegEx match everything
+                        _cacheCtcpSender = ".*";
+                    }
+                    else {
+                        // Wildcard match everything
+                        _cacheCtcpSender = "*";
+                    }
+                    // Clear the types (split is already empty)
+                    _cacheCtcpTypes = split;
+                }
             }
             _type = type;
         }
@@ -315,7 +334,7 @@ public:
         mutable ExpressionMatch _ctcpSenderMatch = {};    ///< Expression match cache for CTCP nick
     };
 
-    typedef QList<IgnoreListItem> IgnoreList;
+    using IgnoreList = QList<IgnoreListItem>;
 
     int indexOf(const QString &ignore) const;
     inline bool contains(const QString &ignore) const { return indexOf(ignore) != -1; }
@@ -389,6 +408,3 @@ signals:
 private:
     IgnoreList _ignoreList;
 };
-
-
-#endif // IGNORELISTMANAGER_H