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
Change-Id: I1198c082a2ee0addbe7c0d2192073b017d9f8dd7
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 496b4294c90ed080ed5b83e1dd465f07652706ea)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2022-07-18 16:22:48 +02:00 committed by Qt Cherry-pick Bot
parent 663e5259f5
commit 2b5b8395e1

View File

@ -532,13 +532,13 @@ qsizetype 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)