diff options
author | Liang Qi <liang.qi@qt.io> | 2020-05-19 15:46:22 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2020-05-20 10:53:19 +0200 |
commit | c944784fbc4be7f72bb9ec9d8cfdb137e1bd3f9d (patch) | |
tree | b609036e04628d8ef690369b77550ffc25ab4a24 /tests/postbuild | |
parent | e9dd3696c7f9860a76f46391b30692ac0dfa6685 (diff) |
Port QRegExp usages to QRegularExpression
Change-Id: Id4a748ea4789d5b13c29ec4444feb23b561bea18
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/postbuild')
-rw-r--r-- | tests/postbuild/bic/qbic.cpp | 15 | ||||
-rw-r--r-- | tests/postbuild/bic/qbic.h | 6 | ||||
-rw-r--r-- | tests/postbuild/bic/tst_bic.cpp | 13 | ||||
-rw-r--r-- | tests/postbuild/guiapplauncher/tst_guiapplauncher.cpp | 19 | ||||
-rw-r--r-- | tests/postbuild/headers/tst_headers.cpp | 22 | ||||
-rw-r--r-- | tests/postbuild/symbols/tst_symbols.cpp | 18 |
6 files changed, 48 insertions, 45 deletions
diff --git a/tests/postbuild/bic/qbic.cpp b/tests/postbuild/bic/qbic.cpp index 4d5fd40f..740e634a 100644 --- a/tests/postbuild/bic/qbic.cpp +++ b/tests/postbuild/bic/qbic.cpp @@ -34,17 +34,17 @@ void QBic::addBlacklistedClass(const QString &wildcard) { - blackList.append(QRegExp(wildcard, Qt::CaseSensitive, QRegExp::Wildcard)); + blackList.append(QRegularExpression(QRegularExpression::anchoredPattern(QRegularExpression::wildcardToRegularExpression(wildcard)))); } -void QBic::addBlacklistedClass(const QRegExp &expression) +void QBic::addBlacklistedClass(const QRegularExpression &expression) { blackList.append(expression); } void QBic::removeBlacklistedClass(const QString &wildcard) { - blackList.removeAll(QRegExp(wildcard, Qt::CaseSensitive, QRegExp::Wildcard)); + blackList.removeAll(QRegularExpression(QRegularExpression::anchoredPattern(QRegularExpression::wildcardToRegularExpression(wildcard)))); } bool QBic::isBlacklisted(const QString &className) const @@ -54,7 +54,7 @@ bool QBic::isBlacklisted(const QString &className) const return true; for (int i = 0; i < blackList.count(); ++i) - if (blackList[i].exactMatch(className)) + if (blackList[i].match(className).hasMatch()) return true; return false; } @@ -206,12 +206,13 @@ QBic::Info QBic::parseOutput(const QByteArray &ba) const const QString className = entry.at(0).mid(6); if (isBlacklisted(className)) continue; - QRegExp rx("size=(\\d+)"); - if (rx.indexIn(entry.at(1)) == -1) { + QRegularExpression rx("size=(\\d+)"); + QRegularExpressionMatch match = rx.match(entry.at(1)); + if (!match.hasMatch()) { qWarning("Could not parse class information for className %s", className.toLatin1().constData()); continue; } - info.classSizes[className] = rx.cap(1).toInt(); + info.classSizes[className] = match.captured(1).toInt(); } else if (entry.at(0).startsWith("Vtable for ")) { const QString className = entry.at(0).mid(11); if (isBlacklisted(className)) diff --git a/tests/postbuild/bic/qbic.h b/tests/postbuild/bic/qbic.h index cbf85890..9c3bf193 100644 --- a/tests/postbuild/bic/qbic.h +++ b/tests/postbuild/bic/qbic.h @@ -31,7 +31,7 @@ #include "QtCore/qhash.h" #include "QtCore/qlist.h" #include "QtCore/qpair.h" -#include "QtCore/qregexp.h" +#include "QtCore/qregularexpression.h" #include "QtCore/qstring.h" #include "QtCore/qstringlist.h" @@ -62,7 +62,7 @@ public: }; void addBlacklistedClass(const QString &wildcard); - void addBlacklistedClass(const QRegExp &expression); + void addBlacklistedClass(const QRegularExpression &expression); void removeBlacklistedClass(const QString &wildcard); bool isBlacklisted(const QString &className) const; @@ -73,7 +73,7 @@ public: SizeDiff diffSizes(const Info &oldLib, const Info &newLib) const; private: - mutable QList<QRegExp> blackList; + mutable QList<QRegularExpression> blackList; }; #endif diff --git a/tests/postbuild/bic/tst_bic.cpp b/tests/postbuild/bic/tst_bic.cpp index 5be1e690..95db11f1 100644 --- a/tests/postbuild/bic/tst_bic.cpp +++ b/tests/postbuild/bic/tst_bic.cpp @@ -71,15 +71,16 @@ bool compilerVersion(const QString &compiler, QString *output, Version *version, *output = QString::fromLocal8Bit(proc.readAllStandardOutput()); // Extract version from last token of first line ("g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2 [build (prerelease)]\n...") - QRegExp versionPattern(QLatin1String("^[^(]+\\([^)]+\\) (\\d+)\\.(\\d+)\\.\\d+.*$")); + QRegularExpression versionPattern(QLatin1String("^[^(]+\\([^)]+\\) (\\d+)\\.(\\d+)\\.\\d+.*$")); Q_ASSERT(versionPattern.isValid()); - if (!versionPattern.exactMatch(*output)) { + QRegularExpressionMatch match = versionPattern.match(*output); + if (!match.hasMatch()) { *errorMessage = compiler + QLatin1String(" produced unexpected output: \"") - + *output + QLatin1String("\", matching up to ") + QString::number(versionPattern.matchedLength()); + + *output + QLatin1String("\", matching up to ") + QString::number(match.capturedLength()); return false; } - version->first = versionPattern.cap(1).toInt(); - version->second = versionPattern.cap(2).toInt(); + version->first = match.captured(1).toInt(); + version->second = match.captured(2).toInt(); return true; #else // !QT_NO_PROCESS Q_UNUSED(compiler) @@ -230,7 +231,7 @@ tst_Bic::tst_Bic(const char *appFilePath) bic.addBlacklistedClass(QLatin1String("QFlags<QFileEngine::FileFlag>")); /* QTest::toString lambda error is false positive */ - bic.addBlacklistedClass(QRegExp(QLatin1String("QTest::toString(const T&) [with T = QUrl]::__lambda0"), Qt::CaseSensitive, QRegExp::FixedString)); + bic.addBlacklistedClass(QRegularExpression::escape(QLatin1String("QTest::toString(const T&) [with T = QUrl]::__lambda0"))); /* Private classes */ bic.addBlacklistedClass(QLatin1String("QBrushData")); diff --git a/tests/postbuild/guiapplauncher/tst_guiapplauncher.cpp b/tests/postbuild/guiapplauncher/tst_guiapplauncher.cpp index 17076d74..c3aa3615 100644 --- a/tests/postbuild/guiapplauncher/tst_guiapplauncher.cpp +++ b/tests/postbuild/guiapplauncher/tst_guiapplauncher.cpp @@ -223,19 +223,18 @@ static QList<Example> readDataEntriesFromFile(const QString &fileName) if (!file.open(QFile::ReadOnly)) return ret; - QByteArray line; - QRegExp lineMatcher("\"([^\"]*)\", *\"([^\"]*)\", *\"([^\"]*)\", *([-0-9]*), *([-0-9]*)"); - for (line = file.readLine(); !line.isEmpty(); line = file.readLine()) { - int matchPos = lineMatcher.indexIn(QString::fromLatin1(line)); - if (matchPos < 0) + QRegularExpression lineMatcher("\"([^\"]*)\", *\"([^\"]*)\", *\"([^\"]*)\", *([-0-9]*), *([-0-9]*)"); + for (QByteArray line = file.readLine(); !line.isEmpty(); line = file.readLine()) { + QRegularExpressionMatch match = lineMatcher.match(QString::fromLatin1(line)); + if (!match.hasMatch()) break; Example example; - example.name = lineMatcher.cap(1).toLatin1(); - example.directory = lineMatcher.cap(2).toLatin1(); - example.binary = lineMatcher.cap(3).toLatin1(); - example.priority = lineMatcher.cap(4).toUInt(); - example.upTimeMS = lineMatcher.cap(5).toInt(); + example.name = match.captured(1).toLatin1(); + example.directory = match.captured(2).toLatin1(); + example.binary = match.captured(3).toLatin1(); + example.priority = match.captured(4).toUInt(); + example.upTimeMS = match.captured(5).toInt(); ret << example; } diff --git a/tests/postbuild/headers/tst_headers.cpp b/tests/postbuild/headers/tst_headers.cpp index e6484d97..53a17974 100644 --- a/tests/postbuild/headers/tst_headers.cpp +++ b/tests/postbuild/headers/tst_headers.cpp @@ -70,8 +70,8 @@ static QStringList getHeaders(const QString &path) QStringList entries = string.split( "\n" ); // We just want to check header files - entries = entries.filter(QRegExp("\\.h$")); - entries = entries.filter(QRegExp("^(?!ui_)")); + entries = entries.filter(QRegularExpression("\\.h$")); + entries = entries.filter(QRegularExpression("^(?!ui_)")); // Recreate the whole file path so we can open the file from disk QStringList result; @@ -167,11 +167,11 @@ QString tst_Headers::explainPrivateSlot(const QString& line) { // Extract private slot from a line like: // Q_PRIVATE_SLOT(d_func(), void fooBar(...)) - QRegExp re("^\\s+Q_PRIVATE_SLOT\\([^,]+,\\s*(.+)\\)\\s*$"); + QRegularExpression re("^\\s+Q_PRIVATE_SLOT\\([^,]+,\\s*(.+)\\)\\s*$"); QString slot = line; - if (re.indexIn(slot) != -1) { - slot = re.cap(1).simplified(); - } + QRegularExpressionMatch match = re.match(slot); + if (match.hasMatch()) + slot = match.captured(1).simplified(); return QString( "Private slot `%1' should be named starting with _q_, to reduce the risk of collisions " @@ -226,16 +226,16 @@ void tst_Headers::macros() // "signals" and "slots" should be banned in public headers // headers which use signals/slots wouldn't compile if Qt is configured with QT_NO_KEYWORDS - QVERIFY2(content.indexOf(QRegExp("\\bslots\\s*:")) == -1, "Header contains `slots' - use `Q_SLOTS' instead!"); - QVERIFY2(content.indexOf(QRegExp("\\bsignals\\s*:")) == -1, "Header contains `signals' - use `Q_SIGNALS' instead!"); + QVERIFY2(content.indexOf(QRegularExpression("\\bslots\\s*:")) == -1, "Header contains `slots' - use `Q_SLOTS' instead!"); + QVERIFY2(content.indexOf(QRegularExpression("\\bsignals\\s*:")) == -1, "Header contains `signals' - use `Q_SIGNALS' instead!"); if (header.contains("/sql/drivers/") || header.contains("/arch/qatomic") - || header.contains(QRegExp("q.*global\\.h$")) + || header.contains(QRegularExpression("q.*global\\.h$")) || header.endsWith("qwindowdefs_win.h")) return; - int beginNamespace = content.indexOf(QRegExp("QT_BEGIN_NAMESPACE(_[A-Z_]+)?")); - int endNamespace = content.lastIndexOf(QRegExp("QT_END_NAMESPACE(_[A-Z_]+)?")); + int beginNamespace = content.indexOf(QRegularExpression("QT_BEGIN_NAMESPACE(_[A-Z_]+)?")); + int endNamespace = content.lastIndexOf(QRegularExpression("QT_END_NAMESPACE(_[A-Z_]+)?")); QVERIFY(beginNamespace != -1); QVERIFY(endNamespace != -1); QVERIFY(beginNamespace < endNamespace); diff --git a/tests/postbuild/symbols/tst_symbols.cpp b/tests/postbuild/symbols/tst_symbols.cpp index 98766654..1f480173 100644 --- a/tests/postbuild/symbols/tst_symbols.cpp +++ b/tests/postbuild/symbols/tst_symbols.cpp @@ -100,16 +100,17 @@ void tst_Symbols::initTestCase() static QString symbolToLine(const QString &symbol, const QString &lib) { // nm outputs the symbol name, the type, the address and the size - QRegExp re("global constructors keyed to ([a-zA-Z_0-9.]*) (.) ([0-f]*) ([0-f]*)"); - if (re.indexIn(symbol) == -1) + QRegularExpression re("global constructors keyed to ([a-zA-Z_0-9.]*) (.) ([0-f]*) ([0-f]*)"); + QRegularExpressionMatch match = re.match(symbol); + if (!match.hasMatch()) return QString(); // address and symbolSize are in hex. Convert to integers bool ok; - int symbolAddress = re.cap(3).toInt(&ok, 16); + int symbolAddress = match.captured(3).toInt(&ok, 16); if (!ok) return QString(); - int symbolSize = re.cap(4).toInt(&ok, 16); + int symbolSize = match.captured(4).toInt(&ok, 16); if (!ok) return QString(); @@ -177,14 +178,15 @@ void tst_Symbols::globalObjects() if (!symbol.startsWith("global constructors keyed to ")) continue; - QRegExp re("global constructors keyed to ([a-zA-Z_0-9.]*)"); - QVERIFY(re.indexIn(symbol) != -1); + QRegularExpression re("global constructors keyed to ([a-zA-Z_0-9.]*)"); + QRegularExpressionMatch match = re.match(symbol); + QVERIFY(match.hasMatch()); - QString cap = re.cap(1); + QString cap = match.captured(1); bool whitelisted = false; foreach (QString white, whitelist) { - if (cap.indexOf(QRegExp(white)) != -1) { + if (cap.indexOf(QRegularExpression(white)) != -1) { whitelisted = true; break; } |