From c90d22f3b269743b4b172ca388dd81832325155b Mon Sep 17 00:00:00 2001 From: jvoisin Date: Thu, 12 Jan 2023 22:41:41 +0100 Subject: [PATCH] Replace usage of QRegularExpression::anchoredPattern with `^` and `$` Using `^` and `$` is shorter than `QRegularExpression::anchoredPattern`, and even allows us in one case to get rid of a trailing `.*`. --- apps/launcher/graphicspage.cpp | 2 +- apps/launcher/utils/textinputdialog.cpp | 3 +-- apps/wizard/inisettings.cpp | 4 ++-- components/config/launchersettings.cpp | 2 +- components/config/settingsbase.hpp | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 261b76416a..e545340c83 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -205,7 +205,7 @@ void Launcher::GraphicsPage::saveSettings() int cHeight = 0; if (standardRadioButton->isChecked()) { - QRegularExpression resolutionRe(QRegularExpression::anchoredPattern(QString("(\\d+) x (\\d+).*"))); + QRegularExpression resolutionRe("^(\\d+) x (\\d+)"); QRegularExpressionMatch match = resolutionRe.match(resolutionComboBox->currentText().simplified()); if (match.hasMatch()) { diff --git a/apps/launcher/utils/textinputdialog.cpp b/apps/launcher/utils/textinputdialog.cpp index 9f9e3e8d13..4510980f5f 100644 --- a/apps/launcher/utils/textinputdialog.cpp +++ b/apps/launcher/utils/textinputdialog.cpp @@ -20,8 +20,7 @@ Launcher::TextInputDialog::TextInputDialog(const QString& title, const QString& label->setText(text); // Line edit - QValidator* validator - = new QRegularExpressionValidator(QRegularExpression("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore + QValidator* validator = new QRegularExpressionValidator(QRegularExpression("^[a-zA-Z0-9_]*$"), this); mLineEdit = new LineEdit(this); mLineEdit->setValidator(validator); mLineEdit->setCompleter(nullptr); diff --git a/apps/wizard/inisettings.cpp b/apps/wizard/inisettings.cpp index 1f8d29f71d..bb379db952 100644 --- a/apps/wizard/inisettings.cpp +++ b/apps/wizard/inisettings.cpp @@ -30,7 +30,7 @@ bool Wizard::IniSettings::readFile(QTextStream& stream) // Look for a square bracket, "'\\[" // that has one or more "not nothing" in it, "([^]]+)" // and is closed with a square bracket, "\\]" - QRegularExpression sectionRe(QRegularExpression::anchoredPattern("^\\[([^]]+)\\]")); + QRegularExpression sectionRe("^\\[([^]]+)\\]$"); // Find any character(s) that is/are not equal sign(s), "[^=]+" // followed by an optional whitespace, an equal sign, and another optional whitespace, "\\s*=\\s*" @@ -75,7 +75,7 @@ bool Wizard::IniSettings::writeFile(const QString& path, QTextStream& stream) // Look for a square bracket, "'\\[" // that has one or more "not nothing" in it, "([^]]+)" // and is closed with a square bracket, "\\]" - QRegularExpression sectionRe(QRegularExpression::anchoredPattern("^\\[([^]]+)\\]")); + QRegularExpression sectionRe("^\\[([^]]+)\\]$"); // Find any character(s) that is/are not equal sign(s), "[^=]+" // followed by an optional whitespace, an equal sign, and another optional whitespace, "\\s*=\\s*" diff --git a/components/config/launchersettings.cpp b/components/config/launchersettings.cpp index 962c1cdbf9..0cea8270aa 100644 --- a/components/config/launchersettings.cpp +++ b/components/config/launchersettings.cpp @@ -47,7 +47,7 @@ QStringList Config::LauncherSettings::subKeys(const QString& key) bool Config::LauncherSettings::writeFile(QTextStream& stream) { QString sectionPrefix; - QRegularExpression sectionRe(QRegularExpression::anchoredPattern("([^/]+)/(.+)$")); + QRegularExpression sectionRe("^([^/]+)/(.+)$"); QMultiMap settings = SettingsBase::getSettings(); QMapIterator i(settings); diff --git a/components/config/settingsbase.hpp b/components/config/settingsbase.hpp index 1bc559b709..068fc68d91 100644 --- a/components/config/settingsbase.hpp +++ b/components/config/settingsbase.hpp @@ -42,7 +42,7 @@ namespace Config QString sectionPrefix; - QRegularExpression sectionRe(QRegularExpression::anchoredPattern("^\\[([^]]+)\\]")); + QRegularExpression sectionRe("^\\[([^]]+)\\]$"); QRegularExpression keyRe("^([^=]+)\\s*=\\s*(.+)$"); while (!stream.atEnd())