summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qlocale.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2020-10-09 15:31:01 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2020-11-08 13:00:17 +0100
commit7d81f21d48dc6d70cf5429e899184acd9ce5f305 (patch)
tree91c728fc1c435dc572338e684cbf2b3b3da51a49 /src/corelib/text/qlocale.cpp
parent297cbd506f1b223d682feae0dbcfe3a08d0ec9b2 (diff)
Always pass index when creating a QLocalePrivate
Previously, two calls using the default locale (which has an index in the locale_data array when it isn't the system locale) neglected to pass the index and the call for the system locale had no idnex, where it should really set the index appropriate to its language, script and country, so that we get appropriate calendar data to go with the system locale. One other place that handled the default locale also neglected to revise the index it was using. Change-Id: I4cc52e2d085a99e61236c91c0ae873b3bde5f11d Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qlocale.cpp')
-rw-r--r--src/corelib/text/qlocale.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp
index 54497c79ec..45d4bd99fb 100644
--- a/src/corelib/text/qlocale.cpp
+++ b/src/corelib/text/qlocale.cpp
@@ -589,8 +589,9 @@ static QLocalePrivate *c_private()
}
static const QLocaleData *systemData();
+static uint defaultIndex();
Q_GLOBAL_STATIC_WITH_ARGS(QExplicitlySharedDataPointer<QLocalePrivate>, systemLocalePrivate,
- (QLocalePrivate::create(systemData())))
+ (QLocalePrivate::create(systemData(), defaultIndex())))
#ifndef QT_NO_SYSTEMLOCALE
/******************************************************************************
@@ -700,6 +701,22 @@ static const QLocaleData *defaultData()
return default_data;
}
+static uint defaultIndex()
+{
+ const QLocaleData *const data = defaultData();
+#ifndef QT_NO_SYSTEMLOCALE
+ if (data == systemData()) {
+ // Work out a suitable index matching the system data, for use when
+ // accessing calendar data, when not fetched from system.
+ return QLocaleData::findLocaleIndex(data->id());
+ }
+#endif
+
+ Q_ASSERT(data >= locale_data);
+ Q_ASSERT(data < locale_data + std::size(locale_data));
+ return data - locale_data;
+}
+
const QLocaleData *QLocaleData::c()
{
Q_ASSERT(locale_index[QLocale::C] == 0);
@@ -726,7 +743,7 @@ QDataStream &operator>>(QDataStream &ds, QLocale &l)
static const int locale_data_size = sizeof(locale_data)/sizeof(QLocaleData) - 1;
Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer<QLocalePrivate>, defaultLocalePrivate,
- (QLocalePrivate::create(defaultData())))
+ (QLocalePrivate::create(defaultData(), defaultIndex())))
static QLocalePrivate *localePrivateByName(const QString &name)
{
@@ -756,6 +773,7 @@ static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Sc
if (defaultLocalePrivate.exists())
numberOptions = defaultLocalePrivate->data()->m_numberOptions;
data = defaultData();
+ index = defaultIndex();
}
return QLocalePrivate::create(data, index, numberOptions);
}