diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2021-08-23 20:28:44 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-08-26 07:34:33 +0000 |
commit | 2ecbc85454d56dfd85c4d4954eb74ed9c2673c71 (patch) | |
tree | 4561c8966e21abfd9185b98691e1f2e63f6809e9 /tests | |
parent | f0101e09d2a2d4987c5f89dcd339a02e7d3c8822 (diff) |
QBA(V)/QS(V)::lastIndexOf: fix the search of 1-char needles
When a needle has length 1 (because it's a QChar/char16_t, or because
it's a string-like of length 1) then an ad-hoc search algorithm is
used. This algorithm had a off-by-one, by not allowing to match at
the last position of a haystack (in case `from` was `haystack.size()`).
That is inconsistent with the general search of substring needles
(and what QByteArray does). Fix that case and amend wrong tests.
This in turn unveiled the fact that the algorithm was unable to cope
with 0-length haystacks (whops), so fix that as well. Drive-by, add a
similar fix for QByteArray.
Amends 6cee204d56205e250b0675c9c6d4dd8a2367f3c4.
Change-Id: I6b3effc4ecd74bcbcd33dd2e550da2df7bf05ae3
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
(cherry picked from commit f0c2c987e3e7eb046303892b1eee4f848759923a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/text/qstring/tst_qstring.cpp | 2 | ||||
-rw-r--r-- | tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp | 6 |
2 files changed, 4 insertions, 4 deletions
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 0cf5f15d74..970c6afb23 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -1721,7 +1721,7 @@ void tst_QString::lastIndexOf_data() QTest::newRow("10") << a << "G" << -1 << int(a.size())-1 << true; QTest::newRow("11") << a << "G" << int(a.size())-1 << int(a.size())-1 << true; - QTest::newRow("12") << a << "G" << int(a.size()) << -1 << true; + QTest::newRow("12") << a << "G" << int(a.size()) << int(a.size())-1 << true; QTest::newRow("13") << a << "A" << 0 << 0 << true; QTest::newRow("14") << a << "A" << -1*int(a.size()) << 0 << true; diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp index 0d4b67b1cc..b60d65af4a 100644 --- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -2437,7 +2437,7 @@ void tst_QStringApiSymmetry::lastIndexOf_data(bool rhsHasVariableLength) } #define ROW(h, n, st, cs, cis) \ - QTest::addRow("haystack: %s, needle: %s", #h, #n) << h << QLatin1String(#h) \ + QTest::addRow("haystack: %s, needle: %s, start %d", #h, #n, st) << h << QLatin1String(#h) \ << n << QLatin1String(#n) \ << qsizetype(st) << qsizetype(cs) << qsizetype(cis) @@ -2454,8 +2454,8 @@ void tst_QStringApiSymmetry::lastIndexOf_data(bool rhsHasVariableLength) ROW(ABCDEFGHIEfGEFG, g, 14, -1, 14); ROW(ABCDEFGHIEfGEFG, G, 13, 11, 11); ROW(ABCDEFGHIEfGEFG, g, 13, -1, 11); - ROW(ABCDEFGHIEfGEFG, G, 15, -1, -1); - ROW(ABCDEFGHIEfGEFG, g, 15, -1, -1); + ROW(ABCDEFGHIEfGEFG, G, 15, 14, 14); + ROW(ABCDEFGHIEfGEFG, g, 15, -1, 14); ROW(ABCDEFGHIEfGEFG, B, 14, 1, 1); ROW(ABCDEFGHIEfGEFG, b, 14, -1, 1); ROW(ABCDEFGHIEfGEFG, B, -1, 1, 1); |