summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qregularexpression
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-05-31 18:04:04 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-05-31 21:46:32 +0200
commit529f052add3edbc1afb063a5cbbb118b67434fb6 (patch)
tree8d4b3c3a961bd4a07e2d03de36e3abf8e283d97a /tests/auto/corelib/text/qregularexpression
parent32a39c4ed1802eab7454d3e6007ff02aa9581b66 (diff)
Port QRegularExpression to QStringView, drop QStringRef
The idea is pretty simple -- add QRegularExpression matching over QStringView. When matching over a QString, keep the string alive (by taking a copy), and set the view onto that string. Otherwise, just use the view provided by the user (who is then responsible for ensuring the data stays valid while matching). Do just minor refactorings to support this use case in a cleaner fashion. In QRegularExpressionMatch drop the QStringRef-returning methods, as they cannot work any more -- in the general case there won't be a QString to build a QStringRef from. [ChangeLog][QtCore][QRegularExpression] All the APIs dealing with QStringRef have been ported to QStringView, following QStringRef deprecation in Qt 6.0. Change-Id: Ic367991d9583cc108c045e4387c9b7288c8f1ffd Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/corelib/text/qregularexpression')
-rw-r--r--tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp
index a12fd636eb..48f6628be1 100644
--- a/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp
+++ b/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp
@@ -217,7 +217,6 @@ void consistencyCheck(const QRegularExpressionMatch &match)
int endPos = match.capturedEnd(i);
int length = match.capturedLength(i);
QString captured = match.captured(i);
- QStringRef capturedRef = match.capturedRef(i);
QStringView capturedView = match.capturedView(i);
if (!captured.isNull()) {
@@ -226,13 +225,11 @@ void consistencyCheck(const QRegularExpressionMatch &match)
QVERIFY(length >= 0);
QVERIFY(endPos >= startPos);
QVERIFY((endPos - startPos) == length);
- QVERIFY(captured == capturedRef);
QVERIFY(captured == capturedView);
} else {
QVERIFY(startPos == -1);
QVERIFY(endPos == -1);
QVERIFY((endPos - startPos) == length);
- QVERIFY(capturedRef.isNull());
QVERIFY(capturedView.isNull());
}
}
@@ -344,10 +341,10 @@ static void testMatch(const QRegularExpression &regexp,
// test with QString as subject type
testMatchImpl<QREMatch>(regexp, matchingMethodForString, subject, offset, matchType, matchOptions, result);
- // test with QStringRef as subject type
+ // test with QStringView as subject type
testMatchImpl<QREMatch>(regexp,
matchingMethodForStringRef,
- QStringRef(&subject, 0, subject.length()),
+ QStringView(subject),
offset,
matchType,
matchOptions,
@@ -355,9 +352,9 @@ static void testMatch(const QRegularExpression &regexp,
}
typedef QRegularExpressionMatch (QRegularExpression::*QREMatchStringPMF)(const QString &, int, QRegularExpression::MatchType, QRegularExpression::MatchOptions) const;
-typedef QRegularExpressionMatch (QRegularExpression::*QREMatchStringRefPMF)(const QStringRef &, int, QRegularExpression::MatchType, QRegularExpression::MatchOptions) const;
+typedef QRegularExpressionMatch (QRegularExpression::*QREMatchStringViewPMF)(QStringView, int, QRegularExpression::MatchType, QRegularExpression::MatchOptions) const;
typedef QRegularExpressionMatchIterator (QRegularExpression::*QREGlobalMatchStringPMF)(const QString &, int, QRegularExpression::MatchType, QRegularExpression::MatchOptions) const;
-typedef QRegularExpressionMatchIterator (QRegularExpression::*QREGlobalMatchStringRefPMF)(const QStringRef &, int, QRegularExpression::MatchType, QRegularExpression::MatchOptions) const;
+typedef QRegularExpressionMatchIterator (QRegularExpression::*QREGlobalMatchStringViewPMF)(QStringView, int, QRegularExpression::MatchType, QRegularExpression::MatchOptions) const;
void tst_QRegularExpression::provideRegularExpressions()
{
@@ -866,7 +863,7 @@ void tst_QRegularExpression::normalMatch()
testMatch<QRegularExpressionMatch>(regexp,
static_cast<QREMatchStringPMF>(&QRegularExpression::match),
- static_cast<QREMatchStringRefPMF>(&QRegularExpression::match),
+ static_cast<QREMatchStringViewPMF>(&QRegularExpression::match),
subject,
offset,
QRegularExpression::NormalMatch,
@@ -1138,7 +1135,7 @@ void tst_QRegularExpression::partialMatch()
testMatch<QRegularExpressionMatch>(regexp,
static_cast<QREMatchStringPMF>(&QRegularExpression::match),
- static_cast<QREMatchStringRefPMF>(&QRegularExpression::match),
+ static_cast<QREMatchStringViewPMF>(&QRegularExpression::match),
subject,
offset,
matchType,
@@ -1415,7 +1412,7 @@ void tst_QRegularExpression::globalMatch()
testMatch<QRegularExpressionMatchIterator>(regexp,
static_cast<QREGlobalMatchStringPMF>(&QRegularExpression::globalMatch),
- static_cast<QREGlobalMatchStringRefPMF>(&QRegularExpression::globalMatch),
+ static_cast<QREGlobalMatchStringViewPMF>(&QRegularExpression::globalMatch),
subject,
offset,
matchType,