diff options
Diffstat (limited to 'src/corelib/text/qlatin1stringview.h')
| -rw-r--r-- | src/corelib/text/qlatin1stringview.h | 25 |
1 files changed, 20 insertions, 5 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); } |
