diff options
author | Christian Stenger <christian.stenger@qt.io> | 2020-07-22 14:54:08 +0200 |
---|---|---|
committer | Christian Stenger <christian.stenger@qt.io> | 2020-07-23 14:47:26 +0000 |
commit | 36caa1f292ddfd45b877d331e6d68f813563d259 (patch) | |
tree | 28b703a7c0beb14466ebc1e2682d3f76837aadbe /src/lib/corelib/tools | |
parent | 7401a6bc4e53d920fd7ced3249c735fd232d191c (diff) |
Replace QRegExp by QRegularExpression
Change-Id: I6c86565b8464efd0b7aec61c12879d3b95a5871c
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/lib/corelib/tools')
-rw-r--r-- | src/lib/corelib/tools/codelocation.cpp | 6 | ||||
-rw-r--r-- | src/lib/corelib/tools/fileinfo.cpp | 13 | ||||
-rw-r--r-- | src/lib/corelib/tools/fileinfo.h | 1 | ||||
-rw-r--r-- | src/lib/corelib/tools/jsliterals.cpp | 4 | ||||
-rw-r--r-- | src/lib/corelib/tools/persistence.cpp | 2 | ||||
-rw-r--r-- | src/lib/corelib/tools/persistence.h | 14 | ||||
-rw-r--r-- | src/lib/corelib/tools/shellutils.cpp | 8 | ||||
-rw-r--r-- | src/lib/corelib/tools/version.cpp | 15 |
8 files changed, 29 insertions, 34 deletions
diff --git a/src/lib/corelib/tools/codelocation.cpp b/src/lib/corelib/tools/codelocation.cpp index 542408795..ebfd5edc6 100644 --- a/src/lib/corelib/tools/codelocation.cpp +++ b/src/lib/corelib/tools/codelocation.cpp @@ -47,7 +47,7 @@ #include <QtCore/qdir.h> #include <QtCore/qjsonobject.h> #include <QtCore/qjsonvalue.h> -#include <QtCore/qregexp.h> +#include <QtCore/qregularexpression.h> #include <QtCore/qshareddata.h> #include <QtCore/qstring.h> @@ -118,9 +118,9 @@ QString CodeLocation::toString() const if (isValid()) { str = QDir::toNativeSeparators(filePath()); QString lineAndColumn; - if (line() > 0 && !str.contains(QRegExp(QStringLiteral(":[0-9]+$")))) + if (line() > 0 && !str.contains(QRegularExpression(QStringLiteral(":[0-9]+$")))) lineAndColumn += QLatin1Char(':') + QString::number(line()); - if (column() > 0 && !str.contains(QRegExp(QStringLiteral(":[0-9]+:[0-9]+$")))) + if (column() > 0 && !str.contains(QRegularExpression(QStringLiteral(":[0-9]+:[0-9]+$")))) lineAndColumn += QLatin1Char(':') + QString::number(column()); str += lineAndColumn; } diff --git a/src/lib/corelib/tools/fileinfo.cpp b/src/lib/corelib/tools/fileinfo.cpp index 8f6b285d4..6fdd90fb1 100644 --- a/src/lib/corelib/tools/fileinfo.cpp +++ b/src/lib/corelib/tools/fileinfo.cpp @@ -47,7 +47,7 @@ #include <QtCore/qdatetime.h> #include <QtCore/qdir.h> #include <QtCore/qfileinfo.h> -#include <QtCore/qregexp.h> +#include <QtCore/qregularexpression.h> #if defined(Q_OS_UNIX) #include <cerrno> @@ -242,17 +242,6 @@ QString FileInfo::resolvePath(const QString &base, const QString &rel, HostOsInf return r; } -bool FileInfo::globMatches(const QRegExp ®exp, const QString &fileName) -{ - const QString pattern = regexp.pattern(); - // May be it's simple wildcard, i.e. "*.cpp"? - if (pattern.startsWith(QLatin1Char('*')) && !isPattern(pattern.midRef(1))) { - // Yes, it's rather simple to just check the extension - return fileName.endsWith(pattern.midRef(1)); - } - return regexp.exactMatch(fileName); -} - #ifdef Q_OS_WIN static QString prependLongPathPrefix(const QString &absolutePath) { diff --git a/src/lib/corelib/tools/fileinfo.h b/src/lib/corelib/tools/fileinfo.h index 9813b69a7..c4ca5931a 100644 --- a/src/lib/corelib/tools/fileinfo.h +++ b/src/lib/corelib/tools/fileinfo.h @@ -79,7 +79,6 @@ public: static bool isPattern(const QString &str); static QString resolvePath(const QString &base, const QString &rel, HostOsInfo::HostOs hostOs = HostOsInfo::hostOs()); - static bool globMatches(const QRegExp &pattern, const QString &subject); static bool isFileCaseCorrect(const QString &filePath); // Symlink-correct check. diff --git a/src/lib/corelib/tools/jsliterals.cpp b/src/lib/corelib/tools/jsliterals.cpp index 74328006c..69d170336 100644 --- a/src/lib/corelib/tools/jsliterals.cpp +++ b/src/lib/corelib/tools/jsliterals.cpp @@ -41,7 +41,7 @@ #include <tools/stringconstants.h> -#include <QtCore/qregexp.h> +#include <QtCore/qregularexpression.h> namespace qbs { @@ -53,7 +53,7 @@ QString toJSLiteral(const bool b) QString toJSLiteral(const QString &str) { QString js = str; - js.replace(QRegExp(QLatin1String("([\\\\\"])")), QLatin1String("\\\\1")); + js.replace(QRegularExpression(QLatin1String("([\\\\\"])")), QLatin1String("\\\\1")); js.prepend(QLatin1Char('"')); js.append(QLatin1Char('"')); return js; diff --git a/src/lib/corelib/tools/persistence.cpp b/src/lib/corelib/tools/persistence.cpp index 3f2b57e01..18145eafb 100644 --- a/src/lib/corelib/tools/persistence.cpp +++ b/src/lib/corelib/tools/persistence.cpp @@ -48,7 +48,7 @@ namespace qbs { namespace Internal { -static const char QBS_PERSISTENCE_MAGIC[] = "QBSPERSISTENCE-128"; +static const char QBS_PERSISTENCE_MAGIC[] = "QBSPERSISTENCE-129"; NoBuildGraphError::NoBuildGraphError(const QString &filePath) : ErrorInfo(Tr::tr("Build graph not found for configuration '%1'. Expected location was '%2'.") diff --git a/src/lib/corelib/tools/persistence.h b/src/lib/corelib/tools/persistence.h index e00310321..f97604b42 100644 --- a/src/lib/corelib/tools/persistence.h +++ b/src/lib/corelib/tools/persistence.h @@ -48,7 +48,7 @@ #include <QtCore/qdatastream.h> #include <QtCore/qflags.h> #include <QtCore/qprocess.h> -#include <QtCore/qregexp.h> +#include <QtCore/qregularexpression.h> #include <QtCore/qstring.h> #include <QtCore/qvariant.h> @@ -426,10 +426,16 @@ template<> struct PPHelper<QVariant> static void load(QVariant &v, PersistentPool *pool) { v = pool->loadVariant(); } }; -template<> struct PPHelper<QRegExp> +template<> struct PPHelper<QRegularExpression> { - static void store(const QRegExp &re, PersistentPool *pool) { pool->store(re.pattern()); } - static void load(QRegExp &re, PersistentPool *pool) { re.setPattern(pool->load<QString>()); } + static void store(const QRegularExpression &re, PersistentPool *pool) + { + pool->store(re.pattern()); + } + static void load(QRegularExpression &re, PersistentPool *pool) + { + re.setPattern(pool->load<QString>()); + } }; template<typename T, typename U> struct PPHelper<std::pair<T, U>> diff --git a/src/lib/corelib/tools/shellutils.cpp b/src/lib/corelib/tools/shellutils.cpp index 33ab2c76c..d032aecac 100644 --- a/src/lib/corelib/tools/shellutils.cpp +++ b/src/lib/corelib/tools/shellutils.cpp @@ -44,7 +44,7 @@ #include "qttools.h" #include <QtCore/qfile.h> -#include <QtCore/qregexp.h> +#include <QtCore/qregularexpression.h> #include <QtCore/qtextstream.h> namespace qbs { @@ -56,7 +56,7 @@ QString shellInterpreter(const QString &filePath) { QTextStream ts(&file); const QString shebang = ts.readLine(); if (shebang.startsWith(QLatin1String("#!"))) { - return (shebang.mid(2).split(QRegExp(QStringLiteral("\\s")), + return (shebang.mid(2).split(QRegularExpression(QStringLiteral("\\s")), QBS_SKIP_EMPTY_PARTS) << QString()).front(); } } @@ -125,9 +125,9 @@ static QString shellQuoteWin(const QString &arg) // The process-level standard quoting allows escaping quotes with backslashes (note // that backslashes don't escape themselves, unless they are followed by a quote). // Consequently, quotes are escaped and their preceding backslashes are doubled. - ret.replace(QRegExp(QLatin1String("(\\\\*)\"")), QLatin1String("\\1\\1\\\"")); + ret.replace(QRegularExpression(QLatin1String("(\\\\*)\"")), QLatin1String("\\1\\1\\\"")); // Trailing backslashes must be doubled as well, as they are followed by a quote. - ret.replace(QRegExp(QLatin1String("(\\\\+)$")), QLatin1String("\\1\\1")); + ret.replace(QRegularExpression(QLatin1String("(\\\\+)$")), QLatin1String("\\1\\1")); // However, the shell also interprets the command, and no backslash-escaping exists // there - a quote always toggles the quoting state, but is nonetheless passed down // to the called process verbatim. In the unquoted state, the circumflex escapes diff --git a/src/lib/corelib/tools/version.cpp b/src/lib/corelib/tools/version.cpp index f653256b3..719bc386f 100644 --- a/src/lib/corelib/tools/version.cpp +++ b/src/lib/corelib/tools/version.cpp @@ -39,7 +39,7 @@ #include "version.h" -#include <QtCore/qregexp.h> +#include <QtCore/qregularexpression.h> #include <QtCore/qstring.h> namespace qbs { @@ -51,13 +51,14 @@ Version Version::fromString(const QString &versionString, bool buildNumberAllowe pattern += QStringLiteral("(?:\\.(\\d+))?"); // Followed by a dot and a number up to two times. if (buildNumberAllowed) pattern += QStringLiteral("(?:[-.](\\d+))?"); // And possibly a dash or dot followed by the build number. - QRegExp rex(pattern); - if (!rex.exactMatch(versionString)) + const QRegularExpression rex(QRegularExpression::anchoredPattern(pattern)); + const QRegularExpressionMatch match = rex.match(versionString); + if (!match.hasMatch()) return Version{}; - const int majorNr = rex.cap(1).toInt(); - const int minorNr = rex.captureCount() >= 2 ? rex.cap(2).toInt() : 0; - const int patchNr = rex.captureCount() >= 3 ? rex.cap(3).toInt() : 0; - const int buildNr = rex.captureCount() >= 4 ? rex.cap(4).toInt() : 0; + const int majorNr = match.captured(1).toInt(); + const int minorNr = match.lastCapturedIndex() >= 2 ? match.captured(2).toInt() : 0; + const int patchNr = match.lastCapturedIndex() >= 3 ? match.captured(3).toInt() : 0; + const int buildNr = match.lastCapturedIndex() >= 4 ? match.captured(4).toInt() : 0; return Version{majorNr, minorNr, patchNr, buildNr}; } |