diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2022-03-03 17:36:49 +0100 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2022-03-09 15:58:47 +0100 |
commit | 82e12c79b2b97bec6b56656c1cb977f2ba942d49 (patch) | |
tree | 8e454dc9ce768fa7cb258ced2b0ae39b13db2198 /src/corelib/text/qstring.cpp | |
parent | 30d28810ee73052338e478a5472933c7b9c7d725 (diff) |
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>
Diffstat (limited to 'src/corelib/text/qstring.cpp')
-rw-r--r-- | src/corelib/text/qstring.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 3aa86c49a9..c0fed806a6 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -10441,6 +10441,17 @@ qsizetype QtPrivate::count(QLatin1String haystack, QStringView needle, Qt::CaseS 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 { // non-L1 needles cannot possibly match in L1-only haystacks |