Add an overload of QStringView::count() for QLatin1String
Required for the API symmetry between QStringView and QLatin1String. [ChangeLog][QtCore][QStringView] Added an overload of QStringView::count() for QLatin1String. Change-Id: Ic49a4b31e8f6f0969eff0f792654d23a60e06c49 Task-numer: QTBUG-98431 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
30d28810ee
commit
82e12c79b2
@ -10441,6 +10441,17 @@ qsizetype QtPrivate::count(QLatin1String haystack, QStringView needle, Qt::CaseS
|
|||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qsizetype QtPrivate::count(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs)
|
||||||
|
{
|
||||||
|
if (haystack.size() < needle.size())
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
QVarLengthArray<char16_t> s(needle.size());
|
||||||
|
qt_from_latin1(s.data(), needle.latin1(), size_t(needle.size()));
|
||||||
|
|
||||||
|
return QtPrivate::count(haystack, QStringView(s.data(), s.size()), cs);
|
||||||
|
}
|
||||||
|
|
||||||
qsizetype QtPrivate::count(QLatin1String haystack, QChar needle, Qt::CaseSensitivity cs) noexcept
|
qsizetype QtPrivate::count(QLatin1String haystack, QChar needle, Qt::CaseSensitivity cs) noexcept
|
||||||
{
|
{
|
||||||
// non-L1 needles cannot possibly match in L1-only haystacks
|
// non-L1 needles cannot possibly match in L1-only haystacks
|
||||||
|
@ -396,6 +396,9 @@ qsizetype QStringView::lastIndexOf(QLatin1String s, Qt::CaseSensitivity cs) cons
|
|||||||
{ return QtPrivate::lastIndexOf(*this, size(), s, cs); }
|
{ return QtPrivate::lastIndexOf(*this, size(), s, cs); }
|
||||||
qsizetype QStringView::lastIndexOf(QLatin1String s, qsizetype from, Qt::CaseSensitivity cs) const noexcept
|
qsizetype QStringView::lastIndexOf(QLatin1String s, qsizetype from, Qt::CaseSensitivity cs) const noexcept
|
||||||
{ return QtPrivate::lastIndexOf(*this, from, s, cs); }
|
{ return QtPrivate::lastIndexOf(*this, from, s, cs); }
|
||||||
|
qsizetype QStringView::count(QLatin1String s, Qt::CaseSensitivity cs) const
|
||||||
|
{ return QtPrivate::count(*this, s, cs); }
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// QAnyStringView members that require QLatin1String
|
// QAnyStringView members that require QLatin1String
|
||||||
|
@ -123,6 +123,7 @@ namespace QtPrivate {
|
|||||||
|
|
||||||
[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QStringView haystack, QChar needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept;
|
[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QStringView haystack, QChar needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept;
|
||||||
[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept;
|
[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept;
|
||||||
|
[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
||||||
[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
||||||
[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
||||||
[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QLatin1String haystack, QChar needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept;
|
[[nodiscard]] Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qsizetype count(QLatin1String haystack, QChar needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept;
|
||||||
|
@ -1152,6 +1152,21 @@ QT_BEGIN_NAMESPACE
|
|||||||
\sa QString::count(), contains(), indexOf()
|
\sa QString::count(), contains(), indexOf()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn qsizetype QStringView::count(QLatin1String l1, Qt::CaseSensitivity cs) const noexcept
|
||||||
|
|
||||||
|
\since 6.4
|
||||||
|
\overload count()
|
||||||
|
|
||||||
|
Returns the number of (potentially overlapping) occurrences of the
|
||||||
|
Latin-1 string \a l1 in this string view.
|
||||||
|
|
||||||
|
If \a cs is Qt::CaseSensitive (default), the search is
|
||||||
|
case sensitive; otherwise the search is case insensitive.
|
||||||
|
|
||||||
|
\sa QString::count(), contains(), indexOf()
|
||||||
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn qint64 QStringView::toLongLong(bool *ok, int base) const
|
\fn qint64 QStringView::toLongLong(bool *ok, int base) const
|
||||||
|
|
||||||
|
@ -341,6 +341,7 @@ public:
|
|||||||
{ return QtPrivate::count(*this, c, cs); }
|
{ return QtPrivate::count(*this, c, cs); }
|
||||||
[[nodiscard]] qsizetype count(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
|
[[nodiscard]] qsizetype count(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
|
||||||
{ return QtPrivate::count(*this, s, cs); }
|
{ return QtPrivate::count(*this, s, cs); }
|
||||||
|
[[nodiscard]] inline qsizetype count(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
||||||
|
|
||||||
[[nodiscard]] qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
|
[[nodiscard]] qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
|
||||||
{ return lastIndexOf(c, -1, cs); }
|
{ return lastIndexOf(c, -1, cs); }
|
||||||
|
@ -738,9 +738,8 @@ private Q_SLOTS:
|
|||||||
|
|
||||||
void count_QStringView_QString_data() { count_data(); }
|
void count_QStringView_QString_data() { count_data(); }
|
||||||
void count_QStringView_QString() { count_impl<QStringView, QString>(); }
|
void count_QStringView_QString() { count_impl<QStringView, QString>(); }
|
||||||
// TODO: enable when QStringView::count(QLatin1String, ...) is implemented
|
void count_QStringView_QLatin1String_data() { count_data(); }
|
||||||
// void count_QStringView_QLatin1String_data() { count_data(); }
|
void count_QStringView_QLatin1String() { count_impl<QStringView, QLatin1String>(); }
|
||||||
// void count_QStringView_QLatin1String() { count_impl<QStringView, QLatin1String>(); }
|
|
||||||
void count_QStringView_QStringView_data() { count_data(); }
|
void count_QStringView_QStringView_data() { count_data(); }
|
||||||
void count_QStringView_QStringView() { count_impl<QStringView, QStringView>(); }
|
void count_QStringView_QStringView() { count_impl<QStringView, QStringView>(); }
|
||||||
void count_QStringView_QChar_data() { count_data(); }
|
void count_QStringView_QChar_data() { count_data(); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user