summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qstring
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-12-07 19:03:10 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-12-09 20:41:18 +0100
commit7c3208c97d2ad2c046908e144325c4ddb1e54876 (patch)
treeaf619067ae0f1bb7fc755e41c27359408d7c45ed /tests/auto/corelib/text/qstring
parent92c066b1e5c1986f6d779613b22e53f58f5236ac (diff)
QString: fix count(QRegularExpression)
There is an off by one in the implementation of count(): a match must be attempted even at the very end of the string, because a 0-length match can happen there. While at it, improve the documentation on the counter-intuitive behavior of count(), which doesn't merely count how many times a regexp matches into a string using ordinary global matching. [ChangeLog][QtCore][QString] Fixed a corner case when using QString::count(QRegularExpression), causing an empty in the last position not to be accounted for in the returned result. Change-Id: I064497839a96979abfbac2d0a96546ce160bbc46 Pick-to: 5.15 6.0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/text/qstring')
-rw-r--r--tests/auto/corelib/text/qstring/tst_qstring.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp
index 04a4469a7d..7c965129f0 100644
--- a/tests/auto/corelib/text/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp
@@ -1714,6 +1714,7 @@ void tst_QString::count()
QCOMPARE(a.count("FG",Qt::CaseInsensitive),3);
QCOMPARE(a.count( QString(), Qt::CaseInsensitive), 16);
QCOMPARE(a.count( "", Qt::CaseInsensitive), 16);
+ QCOMPARE(a.count(QRegularExpression("")), 16);
QCOMPARE(a.count(QRegularExpression("[FG][HI]")), 1);
QCOMPARE(a.count(QRegularExpression("[G][HE]")), 2);
QTest::ignoreMessage(QtWarningMsg, "QString::count: invalid QRegularExpression object");