diff options
| author | Thiago Macieira <[email protected]> | 2023-12-07 15:37:48 -0800 |
|---|---|---|
| committer | Thiago Macieira <[email protected]> | 2025-10-26 15:10:16 -0700 |
| commit | 20ef30472d6f70d63d0db0fdb2def2c90a09d9cc (patch) | |
| tree | d877e33730f69d620575502457e704fc26c99e88 | |
| parent | 60b3466600b3584ad463fdfa245ae49930f134b6 (diff) | |
We can delegate to QByteArrayView, which now has inline versions of
those two functions, so long as the input is Latin1.
Change-Id: Ica7a43f6147b49c187ccfffd179eb0f3748164b2
Reviewed-by: Ahmad Samir <[email protected]>
| -rw-r--r-- | src/corelib/text/qlatin1stringview.h | 25 | ||||
| -rw-r--r-- | src/corelib/text/qlatin1stringview.qdoc | 6 |
2 files changed, 25 insertions, 6 deletions
diff --git a/src/corelib/text/qlatin1stringview.h b/src/corelib/text/qlatin1stringview.h index d76c5da512b..0e9e4fb3699 100644 --- a/src/corelib/text/qlatin1stringview.h +++ b/src/corelib/text/qlatin1stringview.h @@ -8,6 +8,7 @@ #ifndef QLATIN1STRINGVIEW_H #define QLATIN1STRINGVIEW_H +#include <QtCore/qbytearrayview.h> #include <QtCore/qchar.h> #include <QtCore/qcompare.h> #include <QtCore/qcontainerfwd.h> @@ -124,8 +125,14 @@ public: { return QtPrivate::findString(*this, from, s, cs); } [[nodiscard]] qsizetype indexOf(QLatin1StringView s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::findString(*this, from, s, cs); } - [[nodiscard]] qsizetype indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return QtPrivate::findString(*this, from, QStringView(&c, 1), cs); } + [[nodiscard]] qsizetype indexOf(QChar c, qsizetype from = 0) const noexcept + { return c.unicode() <= 0xff ? QByteArrayView(*this).indexOf(char(c.unicode()), from) : -1; } + [[nodiscard]] qsizetype indexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs) const noexcept + { + if (cs == Qt::CaseInsensitive) + return QtPrivate::findString(*this, from, QStringView(&c, 1), cs); + return indexOf(c, from); + } [[nodiscard]] bool contains(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return indexOf(s, 0, cs) != -1; } @@ -142,10 +149,18 @@ public: { return lastIndexOf(s, size(), cs); } [[nodiscard]] qsizetype lastIndexOf(QLatin1StringView s, qsizetype from, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::lastIndexOf(*this, from, s, cs); } - [[nodiscard]] qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + [[nodiscard]] qsizetype lastIndexOf(QChar c) const noexcept + { return lastIndexOf(c, -1); } + [[nodiscard]] qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs) 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(QChar c, qsizetype from) const noexcept + { return c.unicode() <= 0xff ? QByteArrayView(*this).lastIndexOf(char(c.unicode()), from) : -1; } + [[nodiscard]] qsizetype lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs) const noexcept + { + if (cs == Qt::CaseInsensitive) + return QtPrivate::lastIndexOf(*this, from, QStringView(&c, 1), cs); + return lastIndexOf(c, from); + } [[nodiscard]] qsizetype count(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return QtPrivate::count(*this, str, cs); } diff --git a/src/corelib/text/qlatin1stringview.qdoc b/src/corelib/text/qlatin1stringview.qdoc index d28b61c4276..a36d7233c59 100644 --- a/src/corelib/text/qlatin1stringview.qdoc +++ b/src/corelib/text/qlatin1stringview.qdoc @@ -505,7 +505,8 @@ /*! \fn qsizetype QLatin1StringView::indexOf(QStringView str, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const \fn qsizetype QLatin1StringView::indexOf(QLatin1StringView l1, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const - \fn qsizetype QLatin1StringView::indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const + \fn qsizetype QLatin1StringView::indexOf(QChar c, qsizetype from = 0) const + \fn qsizetype QLatin1StringView::indexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs) const \since 5.14 Returns the index position in this Latin-1 string view of the first @@ -540,6 +541,9 @@ /*! \fn qsizetype QLatin1StringView::lastIndexOf(QStringView str, qsizetype from, Qt::CaseSensitivity cs) const \fn qsizetype QLatin1StringView::lastIndexOf(QLatin1StringView l1, qsizetype from, Qt::CaseSensitivity cs) const + \fn qsizetype QLatin1StringView::lastIndexOf(QChar c) const + \fn qsizetype QLatin1StringView::lastIndexOf(QChar c, Qt::CaseSensitivity cs) const + \fn qsizetype QLatin1StringView::lastIndexOf(QChar c, qsizetype from) const \fn qsizetype QLatin1StringView::lastIndexOf(QChar c, qsizetype from, Qt::CaseSensitivity cs) const \since 5.14 |
