diff options
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/text/qstring.h | 5 | ||||
-rw-r--r-- | src/corelib/text/qstringview.cpp | 35 | ||||
-rw-r--r-- | src/corelib/text/qstringview.h | 3 |
3 files changed, 43 insertions, 0 deletions
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index f48777d7f1..7906aeaffc 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -2121,6 +2121,11 @@ QString QLatin1String::arg(Args &&...args) const return QtPrivate::argToQStringDispatch(*this, QtPrivate::qStringLikeToArg(args)...); } +inline qsizetype QStringView::count(QChar c, Qt::CaseSensitivity cs) const noexcept +{ return toString().count(c, cs); } +inline qsizetype QStringView::count(QStringView s, Qt::CaseSensitivity cs) const noexcept +{ return toString().count(s.toString(), cs); } + inline short QStringView::toShort(bool *ok, int base) const { return toString().toShort(ok, base); } inline ushort QStringView::toUShort(bool *ok, int base) const diff --git a/src/corelib/text/qstringview.cpp b/src/corelib/text/qstringview.cpp index f3712a412a..1cbfb90d0f 100644 --- a/src/corelib/text/qstringview.cpp +++ b/src/corelib/text/qstringview.cpp @@ -936,6 +936,41 @@ QT_BEGIN_NAMESPACE */ /*! + \fn qsizetype QStringView::count(QChar ch, Qt::CaseSensitivity cs) const noexcept + + \since 5.15.2 + + Returns the number of occurrences of the character \a ch in the + string reference. + + If \a cs is Qt::CaseSensitive (default), the search is + case sensitive; otherwise the search is case insensitive. + + \note This method has been added in 5.15.2 to simplify writing code that is portable + between Qt 5.15 and Qt 6. The implementation is not tuned for performance in Qt 5. + + \sa QString::count(), contains(), indexOf() +*/ + +/*! + \fn qsizetype QStringView::count(QStringView str, Qt::CaseSensitivity cs) const noexcept + + \since 5.15.2 + \overload + + Returns the number of (potentially overlapping) occurrences of the + string reference \a str in this string reference. + + If \a cs is Qt::CaseSensitive (default), the search is + case sensitive; otherwise the search is case insensitive. + + \note This method has been added in 5.15.2 to simplify writing code that is portable + between Qt 5.15 and Qt 6. The implementation is not tuned for performance in Qt 5. + + \sa QString::count(), contains(), indexOf() +*/ + +/*! \fn qint64 QStringView::toLongLong(bool *ok, int base) const Returns the string converted to a \c{long long} using base \a diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index 5e561d88a8..38a6a43219 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -300,6 +300,9 @@ public: { return indexOf(s, 0, cs) != qsizetype(-1); } Q_REQUIRED_RESULT inline bool contains(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + Q_REQUIRED_RESULT inline qsizetype count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + Q_REQUIRED_RESULT inline qsizetype count(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; + Q_REQUIRED_RESULT qsizetype lastIndexOf(QChar c, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::lastIndexOf(*this, from, QStringView(&c, 1), cs); } Q_REQUIRED_RESULT qsizetype lastIndexOf(QStringView s, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept |