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 <edward.welbourne@qt.io>
This commit is contained in:
parent
59928d23fc
commit
9a9195c806
@ -89,8 +89,9 @@ QT_BEGIN_INCLUDE_NAMESPACE
|
|||||||
#include "qlocale_data_p.h"
|
#include "qlocale_data_p.h"
|
||||||
QT_END_INCLUDE_NAMESPACE
|
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)
|
if (len != 2 && len != 3)
|
||||||
return QLocale::C;
|
return QLocale::C;
|
||||||
ushort uc1 = code[0].toLower().unicode();
|
ushort uc1 = code[0].toLower().unicode();
|
||||||
@ -131,8 +132,9 @@ QLocale::Language QLocalePrivate::codeToLanguage(const QChar *code, int len) Q_D
|
|||||||
return QLocale::C;
|
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)
|
if (len != 4)
|
||||||
return QLocale::AnyScript;
|
return QLocale::AnyScript;
|
||||||
|
|
||||||
@ -150,10 +152,12 @@ QLocale::Script QLocalePrivate::codeToScript(const QChar *code, int len) Q_DECL_
|
|||||||
return QLocale::AnyScript;
|
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)
|
if (len != 2 && len != 3)
|
||||||
return QLocale::AnyCountry;
|
return QLocale::AnyCountry;
|
||||||
|
|
||||||
ushort uc1 = code[0].toUpper().unicode();
|
ushort uc1 = code[0].toUpper().unicode();
|
||||||
ushort uc2 = code[1].toUpper().unicode();
|
ushort uc2 = code[1].toUpper().unicode();
|
||||||
ushort uc3 = len > 2 ? code[2].toUpper().unicode() : 0;
|
ushort uc3 = len > 2 ? code[2].toUpper().unicode() : 0;
|
||||||
|
@ -356,15 +356,9 @@ public:
|
|||||||
static QLatin1String languageToCode(QLocale::Language language);
|
static QLatin1String languageToCode(QLocale::Language language);
|
||||||
static QLatin1String scriptToCode(QLocale::Script script);
|
static QLatin1String scriptToCode(QLocale::Script script);
|
||||||
static QLatin1String countryToCode(QLocale::Country country);
|
static QLatin1String countryToCode(QLocale::Country country);
|
||||||
static QLocale::Language codeToLanguage(const QChar *code, int len) Q_DECL_NOTHROW;
|
static QLocale::Language codeToLanguage(QStringView code) Q_DECL_NOTHROW;
|
||||||
static QLocale::Language codeToLanguage(const QString &code) Q_DECL_NOTHROW { return codeToLanguage(code.data(), code.size()); }
|
static QLocale::Script codeToScript(QStringView code) Q_DECL_NOTHROW;
|
||||||
static QLocale::Language codeToLanguage(const QStringRef &code) Q_DECL_NOTHROW { return codeToLanguage(code.data(), code.size()); }
|
static QLocale::Country codeToCountry(QStringView code) Q_DECL_NOTHROW;
|
||||||
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 void getLangAndCountry(const QString &name, QLocale::Language &lang,
|
static void getLangAndCountry(const QString &name, QLocale::Language &lang,
|
||||||
QLocale::Script &script, QLocale::Country &cntry);
|
QLocale::Script &script, QLocale::Country &cntry);
|
||||||
|
|
||||||
|
@ -386,7 +386,7 @@ static QLocale::Country userCountry()
|
|||||||
const GEOID id = GetUserGeoID(GEOCLASS_NATION);
|
const GEOID id = GetUserGeoID(GEOCLASS_NATION);
|
||||||
wchar_t code[3];
|
wchar_t code[3];
|
||||||
const int size = GetGeoInfo(id, GEO_ISO2, code, 3, 0);
|
const int size = GetGeoInfo(id, GEO_ISO2, code, 3, 0);
|
||||||
return (size == 3) ? QLocalePrivate::codeToCountry(reinterpret_cast<const QChar*>(code), size)
|
return (size == 3) ? QLocalePrivate::codeToCountry(QStringView(code, size))
|
||||||
: QLocale::AnyCountry;
|
: QLocale::AnyCountry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user