From 496b4294c90ed080ed5b83e1dd465f07652706ea Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 18 Jul 2022 16:22:48 +0200 Subject: [PATCH] QLocale: port findTag to std::string_view QStringView lacks the equivalent of find_first_of, so use string_view for now. Fixes an unnecessary QString ctor/dtor call, as well as the int/qsizetype mismatch, looking for which I found this code. The function can now be properly noexcept. Task-number: QTBUG-103531 Pick-to: 6.4 6.3 Change-Id: I1198c082a2ee0addbe7c0d2192073b017d9f8dd7 Reviewed-by: Thiago Macieira --- src/corelib/text/qlocale.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 0bfcba2f97f..82e15186cb9 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -530,13 +530,13 @@ int QLocaleData::findLocaleIndex(QLocaleId lid) return locale_index[fallback]; } -static QStringView findTag(QStringView name) +static QStringView findTag(QStringView name) noexcept { - const QString separators = QStringLiteral("_-.@"); - int i = 0; - while (i < name.size() && !separators.contains(name[i])) - i++; - return name.first(i); + const std::u16string_view v(name.utf16(), size_t(name.size())); + const auto i = v.find_first_of(u"_-.@"); + if (i == std::string_view::npos) + return name; + return name.first(qsizetype(i)); } static bool validTag(QStringView tag)