summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2022-07-05 19:01:08 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2022-07-29 23:04:27 +0200
commite540d4a8647c41a3e710a555f5dcc44edb7dfcb4 (patch)
tree25c6441166d1647b95e8983ac48a2204e3390fe4 /tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp
parent8d6b274fa4c65e87443c0fbf8425229230385405 (diff)
QRegularExpression: introduce (global)matchView
QRegularExpression::match (and globalMatch) is currently overloaded for QString and QStringView. This creates a subtle API asymmetry: QRegularExpression re; auto m1 = re.match(getQString()); // OK auto m2 = re.match(getStdU16String()); // Dangling This goes against our decision that every time that there's a possible lifetime issue at play, it should be "evident". Solving the lifetime issue here is possible, but tricky -- since QRegularExpression is out-of-line, one needs a type-erased container for the input string (basically, std::any) to keep it alive and so on. Instead I went for the simpler solution: deprecate match(QStringView) and introduce matchView(QStringView) (same for globalMatch). This makes it clear that the call is matching over a view and therefore users are supposed to keep the source object alive. Drive-by, remove the documentation that says that the QString overloads might not keep the string alive: they do and forever will. [ChangeLog][QtCore][QRegularExpression] Added the matchView() and globalMatchView() functions that operate on string views. The match(QStringView) and globalMatch(QStringView) overloads have been deprecated. Change-Id: I054b8605c2fdea59b556dcfea8920ef4eee78ee9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp')
-rw-r--r--tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp33
1 files changed, 17 insertions, 16 deletions
diff --git a/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp
index 37fa8147ed..7f3bef66e6 100644
--- a/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp
+++ b/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp
@@ -393,6 +393,7 @@ static void testMatch(const QRegularExpression &regexp,
result);
}
+// ### Qt 7: there should no longer be the need for these
typedef QRegularExpressionMatch (QRegularExpression::*QREMatchStringPMF)(const QString &, qsizetype, QRegularExpression::MatchType, QRegularExpression::MatchOptions) const;
typedef QRegularExpressionMatch (QRegularExpression::*QREMatchStringViewPMF)(QStringView, qsizetype, QRegularExpression::MatchType, QRegularExpression::MatchOptions) const;
typedef QRegularExpressionMatchIterator (QRegularExpression::*QREGlobalMatchStringPMF)(const QString &, qsizetype, QRegularExpression::MatchType, QRegularExpression::MatchOptions) const;
@@ -1096,7 +1097,7 @@ void tst_QRegularExpression::normalMatch()
testMatch<QRegularExpressionMatch>(regexp,
static_cast<QREMatchStringPMF>(&QRegularExpression::match),
- static_cast<QREMatchStringViewPMF>(&QRegularExpression::match),
+ static_cast<QREMatchStringViewPMF>(&QRegularExpression::matchView),
subject,
offset,
QRegularExpression::NormalMatch,
@@ -1368,7 +1369,7 @@ void tst_QRegularExpression::partialMatch()
testMatch<QRegularExpressionMatch>(regexp,
static_cast<QREMatchStringPMF>(&QRegularExpression::match),
- static_cast<QREMatchStringViewPMF>(&QRegularExpression::match),
+ static_cast<QREMatchStringViewPMF>(&QRegularExpression::matchView),
subject,
offset,
matchType,
@@ -1645,7 +1646,7 @@ void tst_QRegularExpression::globalMatch()
testMatch<QRegularExpressionMatchIterator>(regexp,
static_cast<QREGlobalMatchStringPMF>(&QRegularExpression::globalMatch),
- static_cast<QREGlobalMatchStringViewPMF>(&QRegularExpression::globalMatch),
+ static_cast<QREGlobalMatchStringViewPMF>(&QRegularExpression::globalMatchView),
subject,
offset,
matchType,
@@ -1985,7 +1986,7 @@ void tst_QRegularExpression::QStringAndQStringViewEquivalence()
QCOMPARE(match.capturedEnd(), 4);
}
{
- const QRegularExpressionMatch match = re.match(QStringView(subject));
+ const QRegularExpressionMatch match = re.matchView(QStringView(subject));
consistencyCheck(match);
QVERIFY(match.isValid());
QVERIFY(match.hasMatch());
@@ -2003,7 +2004,7 @@ void tst_QRegularExpression::QStringAndQStringViewEquivalence()
QCOMPARE(match.capturedEnd(), 4);
}
{
- const QRegularExpressionMatch match = re.match(QStringView(subject), 1);
+ const QRegularExpressionMatch match = re.matchView(QStringView(subject), 1);
consistencyCheck(match);
QVERIFY(match.isValid());
QVERIFY(match.hasMatch());
@@ -2021,7 +2022,7 @@ void tst_QRegularExpression::QStringAndQStringViewEquivalence()
QCOMPARE(match.capturedEnd(), 6);
}
{
- const QRegularExpressionMatch match = re.match(QStringView(subject).mid(1));
+ const QRegularExpressionMatch match = re.matchView(QStringView(subject).mid(1));
consistencyCheck(match);
QVERIFY(match.isValid());
QVERIFY(match.hasMatch());
@@ -2039,7 +2040,7 @@ void tst_QRegularExpression::QStringAndQStringViewEquivalence()
QCOMPARE(match.capturedEnd(), 6);
}
{
- const QRegularExpressionMatch match = re.match(QStringView(subject).mid(1), 1);
+ const QRegularExpressionMatch match = re.matchView(QStringView(subject).mid(1), 1);
consistencyCheck(match);
QVERIFY(match.isValid());
QVERIFY(match.hasMatch());
@@ -2057,7 +2058,7 @@ void tst_QRegularExpression::QStringAndQStringViewEquivalence()
QCOMPARE(match.capturedEnd(), 7);
}
{
- const QRegularExpressionMatch match = re.match(QStringView(subject), 4);
+ const QRegularExpressionMatch match = re.matchView(QStringView(subject), 4);
consistencyCheck(match);
QVERIFY(match.isValid());
QVERIFY(match.hasMatch());
@@ -2072,7 +2073,7 @@ void tst_QRegularExpression::QStringAndQStringViewEquivalence()
QVERIFY(!match.hasMatch());
}
{
- const QRegularExpressionMatch match = re.match(QStringView(subject).mid(4));
+ const QRegularExpressionMatch match = re.matchView(QStringView(subject).mid(4));
consistencyCheck(match);
QVERIFY(match.isValid());
QVERIFY(!match.hasMatch());
@@ -2105,7 +2106,7 @@ void tst_QRegularExpression::QStringAndQStringViewEquivalence()
QVERIFY(!i.hasNext());
}
{
- QRegularExpressionMatchIterator i = re.globalMatch(QStringView(subject));
+ QRegularExpressionMatchIterator i = re.globalMatchView(QStringView(subject));
QVERIFY(i.isValid());
consistencyCheck(i);
@@ -2157,7 +2158,7 @@ void tst_QRegularExpression::QStringAndQStringViewEquivalence()
QVERIFY(!i.hasNext());
}
{
- QRegularExpressionMatchIterator i = re.globalMatch(QStringView(subject), 1);
+ QRegularExpressionMatchIterator i = re.globalMatchView(QStringView(subject), 1);
QVERIFY(i.isValid());
consistencyCheck(i);
@@ -2199,7 +2200,7 @@ void tst_QRegularExpression::QStringAndQStringViewEquivalence()
QVERIFY(!i.hasNext());
}
{
- QRegularExpressionMatchIterator i = re.globalMatch(QStringView(subject).mid(1));
+ QRegularExpressionMatchIterator i = re.globalMatchView(QStringView(subject).mid(1));
QVERIFY(i.isValid());
consistencyCheck(i);
@@ -2231,7 +2232,7 @@ void tst_QRegularExpression::QStringAndQStringViewEquivalence()
QVERIFY(!i.hasNext());
}
{
- QRegularExpressionMatchIterator i = re.globalMatch(QStringView(subject).mid(1), 1);
+ QRegularExpressionMatchIterator i = re.globalMatchView(QStringView(subject).mid(1), 1);
QVERIFY(i.isValid());
consistencyCheck(i);
@@ -2263,7 +2264,7 @@ void tst_QRegularExpression::QStringAndQStringViewEquivalence()
QVERIFY(!i.hasNext());
}
{
- QRegularExpressionMatchIterator i = re.globalMatch(QStringView(subject).mid(1), 1);
+ QRegularExpressionMatchIterator i = re.globalMatchView(QStringView(subject).mid(1), 1);
QVERIFY(i.isValid());
consistencyCheck(i);
@@ -2296,7 +2297,7 @@ void tst_QRegularExpression::QStringAndQStringViewEquivalence()
QVERIFY(!i.hasNext());
}
{
- QRegularExpressionMatchIterator i = re.globalMatch(QStringView(subject), 4);
+ QRegularExpressionMatchIterator i = re.globalMatchView(QStringView(subject), 4);
QVERIFY(i.isValid());
consistencyCheck(i);
@@ -2318,7 +2319,7 @@ void tst_QRegularExpression::QStringAndQStringViewEquivalence()
QVERIFY(!i.hasNext());
}
{
- QRegularExpressionMatchIterator i = re.globalMatch(QStringView(subject).mid(4));
+ QRegularExpressionMatchIterator i = re.globalMatchView(QStringView(subject).mid(4));
consistencyCheck(i);
QVERIFY(i.isValid());
QVERIFY(!i.hasNext());