summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qlocale.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-07-18 16:22:48 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-08-12 07:54:59 +0200
commit496b4294c90ed080ed5b83e1dd465f07652706ea (patch)
treece17bfe7781b2c5c9d577857f7f182176e3d9380 /src/corelib/text/qlocale.cpp
parent1aa00c993be4d7e27555bcd5c13f945766090b9c (diff)
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 <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qlocale.cpp')
-rw-r--r--src/corelib/text/qlocale.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp
index 0bfcba2f97..82e15186cb 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)