summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qlocale.cpp60
-rw-r--r--src/corelib/tools/qlocale_p.h8
2 files changed, 32 insertions, 36 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;
}
diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h
index 4c0432bba7..9674342307 100644
--- a/src/corelib/tools/qlocale_p.h
+++ b/src/corelib/tools/qlocale_p.h
@@ -151,7 +151,7 @@ struct QLocaleId
QLocaleId withLikelySubtagsAdded() const;
QLocaleId withLikelySubtagsRemoved() const;
- QString bcp47Name() const;
+ QByteArray name(char separator = '-') const;
ushort language_id, script_id, country_id;
};
@@ -212,8 +212,6 @@ public:
: m_index(index), m_numberOptions(numberOptions)
{
m_data = dataPointerForIndex(index);
- m_localeID = bcp47Name().toLatin1();
- m_localeID.replace('-','_');
}
~QLocalePrivate()
@@ -232,7 +230,7 @@ public:
quint16 languageId() const { return m_data->m_language_id; }
quint16 countryId() const { return m_data->m_country_id; }
- QString bcp47Name() const;
+ QByteArray bcp47Name(char separator = '-') const;
// ### QByteArray::fromRawData would be more optimal
inline QString languageCode() const { return QLocalePrivate::languageToCode(QLocale::Language(m_data->m_language_id)); }
@@ -334,11 +332,9 @@ public:
QString dateTimeToString(const QString &format, const QDate *date, const QTime *time,
const QLocale *q) const;
- friend class QLocale;
quint16 m_index;
quint16 m_numberOptions;
const QLocaleData *m_data;
- QByteArray m_localeID;
};
inline char QLocalePrivate::digitToCLocale(QChar in) const