From ecc307ff41884d04ffc71d70968891f7903e22f3 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 1 Dec 2021 17:37:59 +0100 Subject: QString et al: fix lastIndexOf() API asymmetry Commit 6cee204d56205e250b0675c9c6d4dd8a2367f3c4 introduced overloads of lastIndexOf() which drop the 'from' argument, inadvertently fixing QTBUG-80694, but failed to provide the new overloads for all existing lastIndexOf() overloads, making the fix for QTBUG-80694 incomplete. This patch completes the fix, by adding the missing overloads (for char-likes) and also adds the missing (non-regex) tests to tst_qstringapisymmetry. Also amends 1c164ec7f21a78025475c561a70b94d1e3dd6bb6. Fixes: QTBUG-80694 Change-Id: Ib4b3d597d658ce2edf01a2bce0d711ecea593d6e Reviewed-by: Fabian Kosmale --- src/corelib/text/qstring.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/corelib/text/qstring.h') diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 5229c030e2..f53cb869c5 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -169,9 +169,13 @@ public: { return lastIndexOf(s, size(), cs); } [[nodiscard]] qsizetype lastIndexOf(QLatin1String s, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::lastIndexOf(*this, from, s, cs); } - [[nodiscard]] qsizetype lastIndexOf(QChar c, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return lastIndexOf(c, -1, cs); } + [[nodiscard]] qsizetype lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::lastIndexOf(*this, from, QStringView(&c, 1), cs); } - [[nodiscard]] qsizetype lastIndexOf(QLatin1Char c, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] qsizetype lastIndexOf(QLatin1Char c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return lastIndexOf(c, -1, cs); } + [[nodiscard]] qsizetype lastIndexOf(QLatin1Char c, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { char ch = c.toLatin1(); return QtPrivate::lastIndexOf(*this, from, QLatin1String(&ch, 1), cs); } using value_type = const char; @@ -521,7 +525,9 @@ public: #endif [[nodiscard]] qsizetype indexOf(QStringView s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::findString(*this, from, s, cs); } - [[nodiscard]] qsizetype lastIndexOf(QChar c, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + [[nodiscard]] qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return lastIndexOf(c, -1, cs); } + [[nodiscard]] qsizetype lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; [[nodiscard]] qsizetype lastIndexOf(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return lastIndexOf(s, size(), cs); } [[nodiscard]] qsizetype lastIndexOf(QLatin1String s, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; -- cgit v1.2.3