diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2020-05-06 13:58:12 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2020-05-07 15:28:26 +0200 |
commit | d124eeb00c3bd82ddbd44b7749d816313292815c (patch) | |
tree | a6819d692d48dad9b13f1a84590b60160ee9574f /src | |
parent | 1eaf7fd5444f832c9ea820f8087efdd3ac86258f (diff) |
Port qt_string_count() to QStringView
It was not using QStringView API, but immediately dropped to bare
metal operations (reinterpret_cast, ushort), subjecting itself to
ushort -> char16_t issues.
The new formulation avoids low-level primitives.
Change-Id: I8e75c7ea7409b133ff43bf5c829aa1f8f7503f11
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/text/qstring.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 2238b7bbba..440369c674 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -11743,19 +11743,18 @@ static inline qsizetype qt_string_count(QStringView haystack, QStringView needle static inline qsizetype qt_string_count(QStringView haystack, QChar ch, Qt::CaseSensitivity cs) { - ushort c = ch.unicode(); qsizetype num = 0; - const ushort *b = reinterpret_cast<const ushort*>(haystack.data()); - const ushort *i = b + haystack.size(); if (cs == Qt::CaseSensitive) { - while (i != b) - if (*--i == c) + for (QChar c : haystack) { + if (c == ch) ++num; + } } else { - c = foldCase(c); - while (i != b) - if (foldCase(*(--i)) == c) + ch = foldCase(ch); + for (QChar c : haystack) { + if (foldCase(c) == ch) ++num; + } } return num; } |