summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2022-10-19 17:39:23 -0700
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-10-27 16:15:55 +0000
commit3bafb629f186e025297af6f9cf201cfd02d21a14 (patch)
tree85910d5bd64a2c35700a56492364785133e30f37
parent10698b31387fd76c0cbc0da34bc738766c848d23 (diff)
QLocale: merge the code for some system locale queries
QSystemLocale is now defined for QT_NO_SYSTEMLOCALE builds (bootstrap), but no implementation will be present. That's just to get the enum declarations. Change-Id: I3c79b7e08fa346988dfefffd171fa00fde8ab080 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit 089bbfc30758265d3fce804b950f56a15225e32c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/corelib/text/qlocale.cpp71
-rw-r--r--src/corelib/text/qlocale_p.h2
2 files changed, 31 insertions, 42 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp
index 69aef517e2..7734e69422 100644
--- a/src/corelib/text/qlocale.cpp
+++ b/src/corelib/text/qlocale.cpp
@@ -875,29 +875,41 @@ static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Sc
return new QLocalePrivate(data, index, numberOptions);
}
-QString QLocaleData::decimalPoint() const
+static std::optional<QString>
+systemLocaleString(const QLocaleData *that, QSystemLocale::QueryType type)
{
#ifndef QT_NO_SYSTEMLOCALE
- if (this == &systemLocaleData) {
- auto res = systemLocale()->query(QSystemLocale::DecimalPoint).toString();
- if (!res.isEmpty())
- return res;
- }
+ if (that != &systemLocaleData)
+ return std::nullopt;
+
+ QVariant v = systemLocale()->query(type);
+ if (v.metaType() != QMetaType::fromType<QString>())
+ return std::nullopt;
+
+ return v.toString();
+#else
+ Q_UNUSED(that)
+ Q_UNUSED(type)
+ return std::nullopt;
#endif
- return decimalSeparator().getData(single_character_data);
+}
+
+static QString localeString(const QLocaleData *that, QSystemLocale::QueryType type,
+ QLocaleData::DataRange range)
+{
+ if (auto opt = systemLocaleString(that, type))
+ return *opt;
+ return range.getData(single_character_data);
+}
+
+QString QLocaleData::decimalPoint() const
+{
+ return localeString(this, QSystemLocale::DecimalPoint, decimalSeparator());
}
QString QLocaleData::groupSeparator() const
{
- // Empty => don't do grouping
-#ifndef QT_NO_SYSTEMLOCALE
- if (this == &systemLocaleData) {
- QVariant res = systemLocale()->query(QSystemLocale::GroupSeparator);
- if (!res.isNull())
- return res.toString();
- }
-#endif
- return groupDelim().getData(single_character_data);
+ return localeString(this, QSystemLocale::GroupSeparator, groupDelim());
}
QString QLocaleData::percentSign() const
@@ -912,14 +924,7 @@ QString QLocaleData::listSeparator() const
QString QLocaleData::zeroDigit() const
{
-#ifndef QT_NO_SYSTEMLOCALE
- if (this == &systemLocaleData) {
- auto res = systemLocale()->query(QSystemLocale::ZeroDigit).toString();
- if (!res.isEmpty())
- return res;
- }
-#endif
- return zero().getData(single_character_data);
+ return localeString(this, QSystemLocale::ZeroDigit, zero());
}
char32_t QLocaleData::zeroUcs() const
@@ -940,26 +945,12 @@ char32_t QLocaleData::zeroUcs() const
QString QLocaleData::negativeSign() const
{
-#ifndef QT_NO_SYSTEMLOCALE
- if (this == &systemLocaleData) {
- auto res = systemLocale()->query(QSystemLocale::NegativeSign).toString();
- if (!res.isEmpty())
- return res;
- }
-#endif
- return minus().getData(single_character_data);
+ return localeString(this, QSystemLocale::NegativeSign, minus());
}
QString QLocaleData::positiveSign() const
{
-#ifndef QT_NO_SYSTEMLOCALE
- if (this == &systemLocaleData) {
- auto res = systemLocale()->query(QSystemLocale::PositiveSign).toString();
- if (!res.isEmpty())
- return res;
- }
-#endif
- return plus().getData(single_character_data);
+ return localeString(this, QSystemLocale::PositiveSign, plus());
}
QString QLocaleData::exponentSeparator() const
diff --git a/src/corelib/text/qlocale_p.h b/src/corelib/text/qlocale_p.h
index 60408dcae7..121e6123a2 100644
--- a/src/corelib/text/qlocale_p.h
+++ b/src/corelib/text/qlocale_p.h
@@ -31,7 +31,6 @@
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_SYSTEMLOCALE
struct QLocaleData;
// Subclassed by Android platform plugin:
class Q_CORE_EXPORT QSystemLocale
@@ -108,7 +107,6 @@ private:
};
Q_DECLARE_TYPEINFO(QSystemLocale::QueryType, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(QSystemLocale::CurrencyToStringArgument, Q_RELOCATABLE_TYPE);
-#endif
#if QT_CONFIG(icu)
namespace QIcu {