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 +++++++--- src/corelib/tools/qlocale_p.h | 12 +++--------- src/corelib/tools/qtimezoneprivate_win.cpp | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) (limited to 'src') 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; diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h index 1c6e3e850b..2b3c6a07cc 100644 --- a/src/corelib/tools/qlocale_p.h +++ b/src/corelib/tools/qlocale_p.h @@ -356,15 +356,9 @@ public: static QLatin1String languageToCode(QLocale::Language language); static QLatin1String scriptToCode(QLocale::Script script); static QLatin1String countryToCode(QLocale::Country country); - static QLocale::Language codeToLanguage(const QChar *code, int len) Q_DECL_NOTHROW; - static QLocale::Language codeToLanguage(const QString &code) Q_DECL_NOTHROW { return codeToLanguage(code.data(), code.size()); } - static QLocale::Language codeToLanguage(const QStringRef &code) Q_DECL_NOTHROW { return codeToLanguage(code.data(), code.size()); } - static QLocale::Script codeToScript(const QChar *code, int len) Q_DECL_NOTHROW; - static QLocale::Script codeToScript(const QString &code) Q_DECL_NOTHROW { return codeToScript(code.data(), code.size()); } - static QLocale::Script codeToScript(const QStringRef &code) Q_DECL_NOTHROW { return codeToScript(code.data(), code.size()); } - static QLocale::Country codeToCountry(const QChar *code, int len) Q_DECL_NOTHROW; - static QLocale::Country codeToCountry(const QString &code) Q_DECL_NOTHROW { return codeToCountry(code.data(), code.size()); } - static QLocale::Country codeToCountry(const QStringRef &code) Q_DECL_NOTHROW { return codeToCountry(code.data(), code.size()); } + static QLocale::Language codeToLanguage(QStringView code) Q_DECL_NOTHROW; + static QLocale::Script codeToScript(QStringView code) Q_DECL_NOTHROW; + static QLocale::Country codeToCountry(QStringView code) Q_DECL_NOTHROW; static void getLangAndCountry(const QString &name, QLocale::Language &lang, QLocale::Script &script, QLocale::Country &cntry); diff --git a/src/corelib/tools/qtimezoneprivate_win.cpp b/src/corelib/tools/qtimezoneprivate_win.cpp index 16dfaefb74..c6d59be3d8 100644 --- a/src/corelib/tools/qtimezoneprivate_win.cpp +++ b/src/corelib/tools/qtimezoneprivate_win.cpp @@ -386,7 +386,7 @@ static QLocale::Country userCountry() const GEOID id = GetUserGeoID(GEOCLASS_NATION); wchar_t code[3]; const int size = GetGeoInfo(id, GEO_ISO2, code, 3, 0); - return (size == 3) ? QLocalePrivate::codeToCountry(reinterpret_cast(code), size) + return (size == 3) ? QLocalePrivate::codeToCountry(QStringView(code, size)) : QLocale::AnyCountry; } -- cgit v1.2.3