diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2022-12-16 22:15:33 +0200 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2023-01-31 23:56:13 +0200 |
commit | 5353afd7a81169095c0fc57fe18d4da44eed7f92 (patch) | |
tree | bc16060f9816e2f95bf2b2ef75e38d073ff0aa3f /src/corelib/text | |
parent | d4fccc95be46f74878a8e8c1e83193b5d96c84a7 (diff) |
QString: use QtPrivate::qustrchr
Change-Id: I3053da3381fbdd22243683f37dd9f55e58c621dc
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text')
-rw-r--r-- | src/corelib/text/qstring.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 59adcf82f6..d33af45912 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -3707,9 +3707,14 @@ QString& QString::replace(QChar ch, const QString &after, Qt::CaseSensitivity cs QVarLengthArray<size_t> indices; if (cs == Qt::CaseSensitive) { - for (qsizetype i = 0; i < d.size; ++i) - if (d.data()[i] == cc) - indices.push_back(i); + const char16_t *begin = d.begin(); + const char16_t *end = d.end(); + QStringView view(begin, end); + const char16_t *hit = nullptr; + while ((hit = QtPrivate::qustrchr(view, cc)) != end) { + indices.push_back(std::distance(begin, hit)); + view = QStringView(std::next(hit), end); + } } else { for (qsizetype i = 0; i < d.size; ++i) if (QChar::toCaseFolded(d.data()[i]) == cc) |