From da169ee2d90d695ddde721ce30377cb309124bcb Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Sun, 20 Jun 2021 13:56:24 +0300 Subject: [PATCH] Replace QRegExp usages with QRegularExpression QRegExp is deprecated in favor QRegularExpression. It's potentially an api breaking change as QRegularExpression has a different pattern syntax. --- src/rules.cpp | 10 +++++----- src/useractions.cpp | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/rules.cpp b/src/rules.cpp index 2d86073993..86b4322531 100644 --- a/src/rules.cpp +++ b/src/rules.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include @@ -335,7 +335,7 @@ bool Rules::matchWMClass(const QByteArray& match_class, const QByteArray& match_ // TODO optimize? QByteArray cwmclass = wmclasscomplete ? match_name + ' ' + match_class : match_class; - if (wmclassmatch == RegExpMatch && QRegExp(QString::fromUtf8(wmclass)).indexIn(QString::fromUtf8(cwmclass)) == -1) + if (wmclassmatch == RegExpMatch && !QRegularExpression(QString::fromUtf8(wmclass)).match(QString::fromUtf8(cwmclass)).hasMatch()) return false; if (wmclassmatch == ExactMatch && wmclass != cwmclass) return false; @@ -348,7 +348,7 @@ bool Rules::matchWMClass(const QByteArray& match_class, const QByteArray& match_ bool Rules::matchRole(const QByteArray& match_role) const { if (windowrolematch != UnimportantMatch) { - if (windowrolematch == RegExpMatch && QRegExp(QString::fromUtf8(windowrole)).indexIn(QString::fromUtf8(match_role)) == -1) + if (windowrolematch == RegExpMatch && !QRegularExpression(QString::fromUtf8(windowrole)).match(QString::fromUtf8(match_role)).hasMatch()) return false; if (windowrolematch == ExactMatch && windowrole != match_role) return false; @@ -361,7 +361,7 @@ bool Rules::matchRole(const QByteArray& match_role) const bool Rules::matchTitle(const QString& match_title) const { if (titlematch != UnimportantMatch) { - if (titlematch == RegExpMatch && QRegExp(title).indexIn(match_title) == -1) + if (titlematch == RegExpMatch && !QRegularExpression(title).match(match_title).hasMatch()) return false; if (titlematch == ExactMatch && title != match_title) return false; @@ -379,7 +379,7 @@ bool Rules::matchClientMachine(const QByteArray& match_machine, bool local) cons && matchClientMachine("localhost", true)) return true; if (clientmachinematch == RegExpMatch - && QRegExp(QString::fromUtf8(clientmachine)).indexIn(QString::fromUtf8(match_machine)) == -1) + && !QRegularExpression(QString::fromUtf8(clientmachine)).match(QString::fromUtf8(match_machine)).hasMatch()) return false; if (clientmachinematch == ExactMatch && clientmachine != match_machine) diff --git a/src/useractions.cpp b/src/useractions.cpp index 07283f7250..c34561089d 100644 --- a/src/useractions.cpp +++ b/src/useractions.cpp @@ -50,8 +50,8 @@ #include #include #include -#include #include +#include #include #include @@ -1740,15 +1740,16 @@ void AbstractClient::setShortcut(const QString& _cut) updateShortcut(); return; } + const QRegularExpression reg(QStringLiteral("(.*\\+)\\((.*)\\)")); QList< QKeySequence > keys; QStringList groups = cut.split(QStringLiteral(" - ")); for (QStringList::ConstIterator it = groups.constBegin(); it != groups.constEnd(); ++it) { - QRegExp reg(QStringLiteral("(.*\\+)\\((.*)\\)")); - if (reg.indexIn(*it) > -1) { - QString base = reg.cap(1); - QString list = reg.cap(2); + const QRegularExpressionMatch match = reg.match(*it); + if (match.hasMatch()) { + const QString base = match.captured(1); + const QString list = match.captured(2); for (int i = 0; i < list.length(); ++i) {