diff options
author | Christian Stenger <christian.stenger@qt.io> | 2022-10-20 09:47:39 +0200 |
---|---|---|
committer | Christian Stenger <christian.stenger@qt.io> | 2022-10-21 12:18:08 +0200 |
commit | ea36be89d4f93467eab2f43634632023c734f2e3 (patch) | |
tree | 91032e43c1e41edc66ac1d20d005dc8d8c931b9e /src | |
parent | 01e2a2244e3f1e3c8810f19b3f1ec6091a92cb95 (diff) |
Replace QRegExp usages by QRegularExpression
Task-number: QTIFW-1829
Change-Id: I5a48bb5660d6082c1b95247adf84bb3126853aef
Reviewed-by: Katja Marttila <katja.marttila@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/ifwtools/binarycreator.cpp | 6 | ||||
-rw-r--r-- | src/libs/ifwtools/rcc/rcc.cpp | 4 | ||||
-rw-r--r-- | src/libs/ifwtools/repositorygen.cpp | 6 | ||||
-rw-r--r-- | src/libs/installer/binaryformatengine.cpp | 16 | ||||
-rw-r--r-- | src/libs/installer/component.cpp | 3 | ||||
-rw-r--r-- | src/libs/installer/elevatedexecuteoperation.cpp | 9 | ||||
-rw-r--r-- | src/libs/installer/fileutils.cpp | 4 | ||||
-rw-r--r-- | src/libs/installer/globals.cpp | 4 | ||||
-rw-r--r-- | src/libs/installer/globals.h | 4 | ||||
-rw-r--r-- | src/libs/installer/installercalculator.cpp | 10 | ||||
-rw-r--r-- | src/libs/installer/packagemanagercore.cpp | 10 | ||||
-rw-r--r-- | src/libs/installer/packagemanagercoredata.cpp | 4 | ||||
-rw-r--r-- | src/libs/kdtools/sysinfo_x11.cpp | 8 | ||||
-rw-r--r-- | src/libs/kdtools/updatefinder.cpp | 6 |
14 files changed, 49 insertions, 45 deletions
diff --git a/src/libs/ifwtools/binarycreator.cpp b/src/libs/ifwtools/binarycreator.cpp index d7adc2a52..839e469d2 100644 --- a/src/libs/ifwtools/binarycreator.cpp +++ b/src/libs/ifwtools/binarycreator.cpp @@ -43,7 +43,7 @@ #include <QDirIterator> #include <QDomDocument> #include <QProcess> -#include <QRegExp> +#include <QRegularExpression> #include <QSettings> #include <QTemporaryFile> #include <QTemporaryDir> @@ -637,8 +637,8 @@ void QInstallerTools::copyConfigData(const QString &configFile, const QString &t continue; } - QString newName = domElement.text().replace(QRegExp(QLatin1String("\\\\|/|\\.|:")), - QLatin1String("_")); + static const QRegularExpression regex(QLatin1String("\\\\|/|\\.|:")); + QString newName = domElement.text().replace(regex, QLatin1String("_")); QString targetFile; QFileInfo elementFileInfo; diff --git a/src/libs/ifwtools/rcc/rcc.cpp b/src/libs/ifwtools/rcc/rcc.cpp index 16203e2cd..2375c48ea 100644 --- a/src/libs/ifwtools/rcc/rcc.cpp +++ b/src/libs/ifwtools/rcc/rcc.cpp @@ -36,7 +36,7 @@ #include <QtCore/QFile> #include <QtCore/QIODevice> #include <QtCore/QLocale> -#include <QtCore/QRegExp> +#include <QtCore/QRegularExpression> #include <QtCore/QStack> #include <QXmlStreamReader> @@ -958,7 +958,7 @@ bool RCCResourceLibrary::writeInitializer() QString initName = m_initName; if (!initName.isEmpty()) { initName.prepend(QLatin1Char('_')); - initName.replace(QRegExp(QLatin1String("[^a-zA-Z0-9_]")), QLatin1String("_")); + initName.replace(QRegularExpression(QLatin1String("[^a-zA-Z0-9_]")), QLatin1String("_")); } //init diff --git a/src/libs/ifwtools/repositorygen.cpp b/src/libs/ifwtools/repositorygen.cpp index 5bd9fd334..a5e015299 100644 --- a/src/libs/ifwtools/repositorygen.cpp +++ b/src/libs/ifwtools/repositorygen.cpp @@ -43,7 +43,7 @@ #include "updater.h" #include <QtCore/QDirIterator> -#include <QtCore/QRegExp> +#include <QtCore/QRegularExpression> #include <QtXml/QDomDocument> #include <QTemporaryDir> @@ -600,8 +600,8 @@ PackageInfoVector QInstallerTools::createListOfPackages(const QStringList &packa info.version = packageElement.firstChildElement(QLatin1String("Version")).text(); // Version cannot start with comparison characters, be an empty string // or have whitespaces at the beginning or at the end - if (!QRegExp(QLatin1String("(?![<=>\\s]+)(.+)")).exactMatch(info.version) || - (info.version != info.version.trimmed())) { + static const QRegularExpression regex(QLatin1String("^(?![<=>\\s]+)(.+)$")); + if (!regex.match(info.version).hasMatch() || (info.version != info.version.trimmed())) { if (ignoreInvalidPackages) continue; throw QInstaller::Error(QString::fromLatin1("Component version for \"%1\" is invalid! <Version>%2</Version>") diff --git a/src/libs/installer/binaryformatengine.cpp b/src/libs/installer/binaryformatengine.cpp index ec6926031..681e6db79 100644 --- a/src/libs/installer/binaryformatengine.cpp +++ b/src/libs/installer/binaryformatengine.cpp @@ -28,7 +28,7 @@ #include "binaryformatengine.h" -#include <QRegExp> +#include <QRegularExpression> namespace { @@ -263,15 +263,17 @@ QStringList BinaryFormatEngine::entryList(QDir::Filters filters, const QStringLi if (filterNames.isEmpty()) return result; - QList<QRegExp> regexps; - foreach (const QString &i, filterNames) - regexps.append(QRegExp(i, Qt::CaseInsensitive, QRegExp::Wildcard)); + QList<QRegularExpression> regexps; + for (const QString &i : filterNames) { + regexps.append(QRegularExpression(QRegularExpression::wildcardToRegularExpression(i), + QRegularExpression::CaseInsensitiveOption)); + } QStringList entries; - foreach (const QString &i, result) { + for (const QString &i : qAsConst(result)) { bool matched = false; - foreach (const QRegExp ®, regexps) { - matched = reg.exactMatch(i); + for (const QRegularExpression ® : qAsConst(regexps)) { + matched = reg.match(i).hasMatch(); if (matched) break; } diff --git a/src/libs/installer/component.cpp b/src/libs/installer/component.cpp index c7dfa65da..36fadf451 100644 --- a/src/libs/installer/component.cpp +++ b/src/libs/installer/component.cpp @@ -43,7 +43,6 @@ #include <productkeycheck.h> #include <QtCore/QDirIterator> -#include <QtCore/QRegExp> #include <QtCore/QTranslator> #include <QtCore/QRegularExpression> @@ -965,7 +964,7 @@ QStringList Component::archives() const QString pathString = QString::fromLatin1("installer://%1/").arg(name()); QStringList archivesNameList = QDir(pathString).entryList(); //RegExp "^" means line beginning - archivesNameList.replaceInStrings(QRegExp(QLatin1String("^")), pathString); + archivesNameList.replaceInStrings(QRegularExpression(QLatin1String("^")), pathString); return archivesNameList; } diff --git a/src/libs/installer/elevatedexecuteoperation.cpp b/src/libs/installer/elevatedexecuteoperation.cpp index fb1778fe0..092b0f0eb 100644 --- a/src/libs/installer/elevatedexecuteoperation.cpp +++ b/src/libs/installer/elevatedexecuteoperation.cpp @@ -35,7 +35,7 @@ #include <QtCore/QDebug> #include <QtCore/QProcessEnvironment> -#include <QtCore/QRegExp> +#include <QtCore/QRegularExpression> #include <QtCore/QThread> using namespace QInstaller; @@ -137,9 +137,10 @@ int ElevatedExecuteOperation::Private::run(QStringList &arguments, const Operati QList< int > allowedExitCodes; - QRegExp re(QLatin1String("^\\{((-?\\d+,)*-?\\d+)\\}$")); - if (re.exactMatch(args.first())) { - const QStringList numbers = re.cap(1).split(QLatin1Char(',')); + static const QRegularExpression re(QLatin1String("^\\{((-?\\d+,)*-?\\d+)\\}$")); + const QRegularExpressionMatch match = re.match(args.first()); + if (match.hasMatch()) { + const QStringList numbers = match.captured(1).split(QLatin1Char(',')); for(QStringList::const_iterator it = numbers.constBegin(); it != numbers.constEnd(); ++it) allowedExitCodes.push_back(it->toInt()); args.pop_front(); diff --git a/src/libs/installer/fileutils.cpp b/src/libs/installer/fileutils.cpp index 0a2ead07e..dac1c62f6 100644 --- a/src/libs/installer/fileutils.cpp +++ b/src/libs/installer/fileutils.cpp @@ -818,8 +818,8 @@ void QInstaller::copyConfigChildElements(QDomDocument &dom, const QDomNodeList & // Filename may also contain a path relative to source directory but we // copy it strictly into target directory without extra paths - const QString newName = domElement.text() - .replace(QRegExp(QLatin1String("\\\\|/|\\.|:")), QLatin1String("_")); + static const QRegularExpression regex(QLatin1String("\\\\|/|\\.|:")); + const QString newName = domElement.text().replace(regex, QLatin1String("_")); const QString targetFile = targetDir + QDir::separator() + newName; const QFileInfo elementFileInfo = QFileInfo(sourceDir, domElement.text()); diff --git a/src/libs/installer/globals.cpp b/src/libs/installer/globals.cpp index adf1d2f6e..bea299696 100644 --- a/src/libs/installer/globals.cpp +++ b/src/libs/installer/globals.cpp @@ -77,12 +77,12 @@ QStringList loggingCategories() } -Q_GLOBAL_STATIC_WITH_ARGS(QRegExp, staticCommaRegExp, (QLatin1String("(, |,)"))); +Q_GLOBAL_STATIC_WITH_ARGS(QRegularExpression, staticCommaRegExp, (QLatin1String("(, |,)"))); /*! \internal */ -QRegExp commaRegExp() +QRegularExpression commaRegExp() { return *staticCommaRegExp(); } diff --git a/src/libs/installer/globals.h b/src/libs/installer/globals.h index b22331e2c..c815a6e31 100644 --- a/src/libs/installer/globals.h +++ b/src/libs/installer/globals.h @@ -30,7 +30,7 @@ #include "installer_global.h" -#include <QRegExp> +#include <QRegularExpression> #include <QLoggingCategory> namespace QInstaller { @@ -43,7 +43,7 @@ INSTALLER_EXPORT Q_DECLARE_LOGGING_CATEGORY(lcDeveloperBuild) QStringList INSTALLER_EXPORT loggingCategories(); -QRegExp INSTALLER_EXPORT commaRegExp(); +QRegularExpression INSTALLER_EXPORT commaRegExp(); QString htmlToString(const QString &html); QString enumToString(const QMetaObject& metaObject, const char *enumerator, int key); diff --git a/src/libs/installer/installercalculator.cpp b/src/libs/installer/installercalculator.cpp index 48c90621b..83efeb468 100644 --- a/src/libs/installer/installercalculator.cpp +++ b/src/libs/installer/installercalculator.cpp @@ -208,11 +208,13 @@ bool InstallerCalculator::appendComponentToInstall(Component *component, const Q PackageManagerCore::parseNameAndVersion(dependencyComponentName, &requiredName, &requiredVersion); if (!requiredVersion.isEmpty() && !dependencyComponent->value(scInstalledVersion).isEmpty()) { - QRegExp compEx(QLatin1String("([<=>]+)(.*)")); - const QString installedVersion = compEx.exactMatch(dependencyComponent->value(scInstalledVersion)) ? - compEx.cap(2) : dependencyComponent->value(scInstalledVersion); + static const QRegularExpression compEx(QLatin1String("^([<=>]+)(.*)$")); + QRegularExpressionMatch match = compEx.match(dependencyComponent->value(scInstalledVersion)); + const QString installedVersion = match.hasMatch() + ? match.captured(2) : dependencyComponent->value(scInstalledVersion); - requiredVersion = compEx.exactMatch(requiredVersion) ? compEx.cap(2) : requiredVersion; + match = compEx.match(requiredVersion); + requiredVersion = match.hasMatch() ? match.captured(2) : requiredVersion; if (KDUpdater::compareVersion(requiredVersion, installedVersion) >= 1 ) { isUpdateRequired = true; diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp index 48d071321..5285f6958 100644 --- a/src/libs/installer/packagemanagercore.cpp +++ b/src/libs/installer/packagemanagercore.cpp @@ -54,7 +54,6 @@ #include <QtConcurrentRun> #include <QtCore/QMutex> -#include <QtCore/QRegExp> #include <QtCore/QSettings> #include <QtCore/QTemporaryFile> #include <QtCore/QTextCodec> @@ -2075,7 +2074,7 @@ QList<Component *> PackageManagerCore::components(ComponentTypes mask, const QSt QRegularExpression re(regexp); QList<Component*>::iterator iter = components.begin(); while (iter != components.end()) { - if (!re.match(iter.i->t()->name()).hasMatch()) + if (!re.match((*iter)->name()).hasMatch()) iter = components.erase(iter); else iter++; @@ -3362,9 +3361,10 @@ bool PackageManagerCore::performOperation(const QString &name, const QStringList */ bool PackageManagerCore::versionMatches(const QString &version, const QString &requirement) { - QRegExp compEx(QLatin1String("([<=>]+)(.*)")); - const QString comparator = compEx.exactMatch(requirement) ? compEx.cap(1) : QLatin1String("="); - const QString ver = compEx.exactMatch(requirement) ? compEx.cap(2) : requirement; + static const QRegularExpression compEx(QLatin1String("^([<=>]+)(.*)$")); + const QRegularExpressionMatch match = compEx.match(requirement); + const QString comparator = match.hasMatch() ? match.captured(1) : QLatin1String("="); + const QString ver = match.hasMatch() ? match.captured(2) : requirement; const bool allowEqual = comparator.contains(QLatin1Char('=')); const bool allowLess = comparator.contains(QLatin1Char('<')); diff --git a/src/libs/installer/packagemanagercoredata.cpp b/src/libs/installer/packagemanagercoredata.cpp index fa3440a72..ff246cb71 100644 --- a/src/libs/installer/packagemanagercoredata.cpp +++ b/src/libs/installer/packagemanagercoredata.cpp @@ -34,7 +34,7 @@ #include <QDesktopServices> #include <QDir> -#include <QRegExp> +#include <QRegularExpression> #include <QSettings> #ifdef Q_OS_WIN @@ -250,7 +250,7 @@ QVariant PackageManagerCoreData::value(const QString &key, const QVariant &_defa #ifdef Q_OS_WIN if (!m_variables.contains(key)) { - static const QRegExp regex(QLatin1String("\\\\|/")); + static const QRegularExpression regex(QLatin1String("\\\\|/")); const QString filename = key.section(regex, 0, -2); const QString regKey = key.section(regex, -1); const QSettingsWrapper registry(filename, format); diff --git a/src/libs/kdtools/sysinfo_x11.cpp b/src/libs/kdtools/sysinfo_x11.cpp index a59fd150b..24ef099ca 100644 --- a/src/libs/kdtools/sysinfo_x11.cpp +++ b/src/libs/kdtools/sysinfo_x11.cpp @@ -40,7 +40,7 @@ #include <QtCore/QTextStream> #include <QtCore/QDir> #include <QtCore/QFileInfo> -#include <QtCore/QRegExp> +#include <QtCore/QRegularExpression> namespace KDUpdater { @@ -124,9 +124,9 @@ QList<ProcessInfo> runningProcesses() QList<ProcessInfo> processes; QDir procDir(QLatin1String("/proc")); const QFileInfoList procCont = procDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Readable); - QRegExp validator(QLatin1String("[0-9]+")); - Q_FOREACH (const QFileInfo &info, procCont) { - if (validator.exactMatch(info.fileName())) { + static const QRegularExpression validator(QLatin1String("^[0-9]+$")); + for (const QFileInfo &info : procCont) { + if (validator.match(info.fileName()).hasMatch()) { const QString linkPath = QDir(info.absoluteFilePath()).absoluteFilePath(QLatin1String("exe")); const QFileInfo linkInfo(linkPath); if (linkInfo.exists()) { diff --git a/src/libs/kdtools/updatefinder.cpp b/src/libs/kdtools/updatefinder.cpp index b1070c742..a45e9e3d0 100644 --- a/src/libs/kdtools/updatefinder.cpp +++ b/src/libs/kdtools/updatefinder.cpp @@ -39,7 +39,7 @@ #include <QCoreApplication> #include <QFileInfo> -#include <QRegExp> +#include <QRegularExpression> using namespace KDUpdater; using namespace QInstaller; @@ -589,8 +589,8 @@ int KDUpdater::compareVersion(const QString &v1, const QString &v2) return 0; // Split version components across ".", "-" or "_" - QStringList v1_comps = v1.split(QRegExp(QLatin1String( "\\.|-|_"))); - QStringList v2_comps = v2.split(QRegExp(QLatin1String( "\\.|-|_"))); + QStringList v1_comps = v1.split(QRegularExpression(QLatin1String( "\\.|-|_"))); + QStringList v2_comps = v2.split(QRegularExpression(QLatin1String( "\\.|-|_"))); // Check each component of the version int index = 0; |