diff options
Diffstat (limited to 'src/corelib/tools/qlocale.cpp')
-rw-r--r-- | src/corelib/tools/qlocale.cpp | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 4aaa1af688..b5f983899a 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -284,51 +284,51 @@ QLocaleId QLocaleId::withLikelySubtagsRemoved() const return max; } -QString QLocaleId::bcp47Name() const +QByteArray QLocaleId::name(char separator) const { if (language_id == QLocale::AnyLanguage) - return QString(); + return QByteArray(); if (language_id == QLocale::C) - return QStringLiteral("C"); + return QByteArrayLiteral("C"); - const unsigned char *lang = language_code_list + 3*uint(language_id); + const unsigned char *lang = language_code_list + 3 * language_id; const unsigned char *script = - (script_id != QLocale::AnyScript ? script_code_list + 4*uint(script_id) : 0); + (script_id != QLocale::AnyScript ? script_code_list + 4 * script_id : 0); const unsigned char *country = - (country_id != QLocale::AnyCountry ? country_code_list + 3*uint(country_id) : 0); + (country_id != QLocale::AnyCountry ? country_code_list + 3 * country_id : 0); char len = (lang[2] != 0 ? 3 : 2) + (script ? 4+1 : 0) + (country ? (country[2] != 0 ? 3 : 2)+1 : 0); - QString name(len, Qt::Uninitialized); - QChar *uc = name.data(); - *uc++ = ushort(lang[0]); - *uc++ = ushort(lang[1]); + QByteArray name(len, Qt::Uninitialized); + char *uc = name.data(); + *uc++ = lang[0]; + *uc++ = lang[1]; if (lang[2] != 0) - *uc++ = ushort(lang[2]); + *uc++ = lang[2]; if (script) { - *uc++ = QLatin1Char('-'); - *uc++ = ushort(script[0]); - *uc++ = ushort(script[1]); - *uc++ = ushort(script[2]); - *uc++ = ushort(script[3]); + *uc++ = separator; + *uc++ = script[0]; + *uc++ = script[1]; + *uc++ = script[2]; + *uc++ = script[3]; } if (country) { - *uc++ = QLatin1Char('-'); - *uc++ = ushort(country[0]); - *uc++ = ushort(country[1]); + *uc++ = separator; + *uc++ = country[0]; + *uc++ = country[1]; if (country[2] != 0) - *uc++ = ushort(country[2]); + *uc++ = country[2]; } return name; } -QString QLocalePrivate::bcp47Name() const +QByteArray QLocalePrivate::bcp47Name(char separator) const { if (m_data->m_language_id == QLocale::AnyLanguage) - return QString(); + return QByteArray(); if (m_data->m_language_id == QLocale::C) - return QStringLiteral("C"); + return QByteArrayLiteral("C"); QLocaleId localeId = QLocaleId::fromIds(m_data->m_language_id, m_data->m_script_id, m_data->m_country_id); - return localeId.withLikelySubtagsRemoved().bcp47Name(); + return localeId.withLikelySubtagsRemoved().name(separator); } const QLocaleData *QLocaleData::findLocaleData(QLocale::Language language, QLocale::Script script, QLocale::Country country) @@ -1080,7 +1080,7 @@ QString QLocale::name() const */ QString QLocale::bcp47Name() const { - return d->bcp47Name(); + return QString::fromLatin1(d->bcp47Name()); } /*! @@ -2494,7 +2494,7 @@ QString QLocale::toUpper(const QString &str) const { #ifdef QT_USE_ICU bool ok = true; - QString result = QIcu::toUpper(d->m_localeID, str, &ok); + QString result = QIcu::toUpper(d->bcp47Name('_'), str, &ok); if (ok) return result; // else fall through and use Qt's toUpper @@ -2511,7 +2511,7 @@ QString QLocale::toLower(const QString &str) const { #ifdef QT_USE_ICU bool ok = true; - QString result = QIcu::toLower(d->m_localeID, str, &ok); + const QString result = QIcu::toLower(d->bcp47Name('_'), str, &ok); if (ok) return result; // else fall through and use Qt's toUpper @@ -3662,14 +3662,14 @@ QStringList QLocale::uiLanguages() const const QLocaleId min = max.withLikelySubtagsRemoved(); QStringList uiLanguages; - uiLanguages.append(min.bcp47Name()); + uiLanguages.append(QString::fromLatin1(min.name())); if (id.script_id) { id.script_id = 0; if (id != min && id.withLikelySubtagsAdded() == max) - uiLanguages.append(id.bcp47Name()); + uiLanguages.append(QString::fromLatin1(id.name())); } if (max != min && max != id) - uiLanguages.append(max.bcp47Name()); + uiLanguages.append(QString::fromLatin1(max.name())); return uiLanguages; } |