From 9a9195c8060d904dfad4ad9f51b5575d434a6037 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 30 Jan 2017 14:55:50 +0100 Subject: Make QLocalePrivate::codeTo*() take QStringViews ... and remove now-superfluous overloads. Adapt the sole user of the (QChar*, int) overload to construct a QStringView first, which removes the ugly cast at the call site. Change-Id: Ie5249d4b1b82d471896548e8a7d83c130ae28130 Reviewed-by: Edward Welbourne --- src/corelib/tools/qlocale.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/corelib/tools/qlocale.cpp') diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 35aa0df0ef..da534908d4 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -89,8 +89,9 @@ QT_BEGIN_INCLUDE_NAMESPACE #include "qlocale_data_p.h" QT_END_INCLUDE_NAMESPACE -QLocale::Language QLocalePrivate::codeToLanguage(const QChar *code, int len) Q_DECL_NOTHROW +QLocale::Language QLocalePrivate::codeToLanguage(QStringView code) Q_DECL_NOTHROW { + const auto len = code.size(); if (len != 2 && len != 3) return QLocale::C; ushort uc1 = code[0].toLower().unicode(); @@ -131,8 +132,9 @@ QLocale::Language QLocalePrivate::codeToLanguage(const QChar *code, int len) Q_D return QLocale::C; } -QLocale::Script QLocalePrivate::codeToScript(const QChar *code, int len) Q_DECL_NOTHROW +QLocale::Script QLocalePrivate::codeToScript(QStringView code) Q_DECL_NOTHROW { + const auto len = code.size(); if (len != 4) return QLocale::AnyScript; @@ -150,10 +152,12 @@ QLocale::Script QLocalePrivate::codeToScript(const QChar *code, int len) Q_DECL_ return QLocale::AnyScript; } -QLocale::Country QLocalePrivate::codeToCountry(const QChar *code, int len) Q_DECL_NOTHROW +QLocale::Country QLocalePrivate::codeToCountry(QStringView code) Q_DECL_NOTHROW { + const auto len = code.size(); if (len != 2 && len != 3) return QLocale::AnyCountry; + ushort uc1 = code[0].toUpper().unicode(); ushort uc2 = code[1].toUpper().unicode(); ushort uc3 = len > 2 ? code[2].toUpper().unicode() : 0; -- cgit v1.2.3