summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlocale.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qlocale.cpp')
-rw-r--r--src/corelib/tools/qlocale.cpp46
1 files changed, 35 insertions, 11 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index 824b70c3fd..890a8fb95d 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -42,6 +42,7 @@
#include "qdatastream.h"
#include "qdebug.h"
+#include "qhashfunctions.h"
#include "qstring.h"
#include "qlocale.h"
#include "qlocale_p.h"
@@ -88,9 +89,9 @@ QLocale::Language QLocalePrivate::codeToLanguage(const QString &code)
int len = code.length();
if (len != 2 && len != 3)
return QLocale::C;
- ushort uc1 = len-- > 0 ? code[0].toLower().unicode() : 0;
- ushort uc2 = len-- > 0 ? code[1].toLower().unicode() : 0;
- ushort uc3 = len-- > 0 ? code[2].toLower().unicode() : 0;
+ ushort uc1 = code[0].toLower().unicode();
+ ushort uc2 = code[1].toLower().unicode();
+ ushort uc3 = len > 2 ? code[2].toLower().unicode() : 0;
const unsigned char *c = language_code_list;
for (; *c != 0; c += 3) {
@@ -115,6 +116,13 @@ QLocale::Language QLocalePrivate::codeToLanguage(const QString &code)
Q_STATIC_ASSERT(QLocale::Moldavian == QLocale::Romanian);
return QLocale::Moldavian;
}
+ // Android uses the following deprecated codes
+ if (uc1 == 'i' && uc2 == 'w' && uc3 == 0) // iw -> he
+ return QLocale::Hebrew;
+ if (uc1 == 'i' && uc2 == 'n' && uc3 == 0) // in -> id
+ return QLocale::Indonesian;
+ if (uc1 == 'j' && uc2 == 'i' && uc3 == 0) // ji -> yi
+ return QLocale::Yiddish;
return QLocale::C;
}
@@ -144,9 +152,9 @@ QLocale::Country QLocalePrivate::codeToCountry(const QString &code)
int len = code.length();
if (len != 2 && len != 3)
return QLocale::AnyCountry;
- ushort uc1 = len-- > 0 ? code[0].toUpper().unicode() : 0;
- ushort uc2 = len-- > 0 ? code[1].toUpper().unicode() : 0;
- ushort uc3 = len-- > 0 ? code[2].toUpper().unicode() : 0;
+ ushort uc1 = code[0].toUpper().unicode();
+ ushort uc2 = code[1].toUpper().unicode();
+ ushort uc3 = len > 2 ? code[2].toUpper().unicode() : 0;
const unsigned char *c = country_code_list;
for (; *c != 0; c += 3) {
@@ -420,7 +428,7 @@ bool qt_splitLocaleName(const QString &name, QString &lang, QString &script, QSt
state = ScriptState;
break;
case ScriptState: {
- QString scripts = QString::fromLatin1((const char *)script_code_list, sizeof(script_code_list));
+ QString scripts = QString::fromLatin1((const char *)script_code_list, sizeof(script_code_list) - 1);
if (value.length() == 4 && scripts.indexOf(value) % 4 == 0) {
// script name is always 4 characters
script = value;
@@ -525,7 +533,7 @@ static uint default_number_options = 0;
static const QLocaleData *const c_data = locale_data;
static QLocalePrivate *c_private()
{
- static QLocalePrivate c_locale = { c_data, Q_BASIC_ATOMIC_INITIALIZER(1), 0 };
+ static QLocalePrivate c_locale = { c_data, Q_BASIC_ATOMIC_INITIALIZER(1), QLocale::OmitGroupSeparator };
return &c_locale;
}
@@ -697,7 +705,8 @@ static QLocalePrivate *localePrivateByName(const QString &name)
{
if (name == QLatin1String("C"))
return c_private();
- return QLocalePrivate::create(findLocaleData(name));
+ const QLocaleData *data = findLocaleData(name);
+ return QLocalePrivate::create(data, data->m_language_id == QLocale::C ? QLocale::OmitGroupSeparator : 0);
}
static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Script script,
@@ -866,6 +875,21 @@ bool QLocale::operator!=(const QLocale &other) const
}
/*!
+ \since 5.6
+ \relates QLocale
+
+ Returns the hash value for \a key, using
+ \a seed to seed the calculation.
+*/
+uint qHash(const QLocale &key, uint seed) Q_DECL_NOTHROW
+{
+ QtPrivate::QHashCombine hash;
+ seed = hash(seed, key.d->m_data);
+ seed = hash(seed, key.d->m_numberOptions);
+ return seed;
+}
+
+/*!
\since 4.2
Sets the \a options related to number conversions for this
@@ -2726,9 +2750,9 @@ QString QLocaleData::doubleToString(const QChar _zero, const QChar plus, const Q
const QChar exponential, const QChar group, const QChar decimal,
double d, int precision, DoubleForm form, int width, unsigned flags)
{
- if (precision == -1)
+ if (precision < 0)
precision = 6;
- if (width == -1)
+ if (width < 0)
width = 0;
bool negative = false;