summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qlocale_p.h
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2020-01-08 14:17:09 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2020-01-30 17:58:40 +0100
commitc0f041fcdf9573c0777fd19a0ce012fedf83fec4 (patch)
treeac276ea9c200edf1b21b0133844b785cb1af2968 /src/corelib/text/qlocale_p.h
parent4e84a8b29f13169a75c734920e953d3157768bca (diff)
Refactor QLocale's data access to be less verbose
Add QLocaleData::DataRange and methods returning it, to package each of the m_*_idx, m_*_size pairs of data members, to simplify access to these data. This extends the experiment started in QCalendarLocale, which is now adapted to use the new DataRange also. Two static functions of qlocale.cpp are replaced by methods of DataRange, saving considerable duplication of long member names in callers. Change-Id: Iad9899ba72f00522594b55a0402baec47491999c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/text/qlocale_p.h')
-rw-r--r--src/corelib/text/qlocale_p.h71
1 files changed, 70 insertions, 1 deletions
diff --git a/src/corelib/text/qlocale_p.h b/src/corelib/text/qlocale_p.h
index 938d7bbb6a..271234266b 100644
--- a/src/corelib/text/qlocale_p.h
+++ b/src/corelib/text/qlocale_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2019 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
@@ -288,6 +288,75 @@ public:
Q_CORE_EXPORT bool validateChars(QStringView str, NumberMode numMode, QByteArray *buff, int decDigits = -1,
QLocale::NumberOptions number_options = QLocale::DefaultNumberOptions) const;
+ struct DataRange
+ {
+ quint16 offset;
+ quint16 size;
+ QString getData(const ushort *table) const
+ {
+ return size > 0
+ ? QString::fromRawData(reinterpret_cast<const QChar *>(table + offset), size)
+ : QString();
+ }
+ QStringView viewData(const ushort *table) const
+ {
+ return { reinterpret_cast<const QChar *>(table + offset), size };
+ }
+ QString getListEntry(const ushort *table, int index) const
+ {
+ return listEntry(table, index).getData(table);
+ }
+ QStringView viewListEntry(const ushort *table, int index) const
+ {
+ return listEntry(table, index).viewData(table);
+ }
+ private:
+ DataRange listEntry(const ushort *table, int index) const
+ {
+ const ushort separator = ';';
+ quint16 i = 0;
+ while (index > 0 && i < size) {
+ if (table[offset + i] == separator)
+ index--;
+ i++;
+ }
+ quint16 end = i;
+ while (end < size && table[offset + end] != separator)
+ end++;
+ return { quint16(offset + i), quint16(end - i) };
+ }
+ };
+#define rangeGetter(name, stem) \
+ DataRange name() const { return { m_ ## stem ## _idx, m_ ## stem ## _size }; }
+
+ rangeGetter(startListPattern, list_pattern_part_start)
+ rangeGetter(midListPattern, list_pattern_part_mid)
+ rangeGetter(endListPattern, list_pattern_part_end)
+ rangeGetter(pairListPattern, list_pattern_part_two)
+ rangeGetter(shortDateFormat, short_date_format)
+ rangeGetter(longDateFormat, long_date_format)
+ rangeGetter(shortTimeFormat, short_time_format)
+ rangeGetter(longTimeFormat, long_time_format)
+ rangeGetter(narrowDayNamesStandalone, standalone_narrow_day_names)
+ rangeGetter(shortDayNamesStandalone, standalone_short_day_names)
+ rangeGetter(longDayNamesStandalone, standalone_long_day_names)
+ rangeGetter(narrowDayNames, narrow_day_names)
+ rangeGetter(shortDayNames, short_day_names)
+ rangeGetter(longDayNames, long_day_names)
+ rangeGetter(anteMeridiem, am)
+ rangeGetter(postMeridiem, pm)
+ rangeGetter(byteCount, byte)
+ rangeGetter(byteAmountSI, byte_si_quantified)
+ rangeGetter(byteAmountIEC, byte_iec_quantified)
+ rangeGetter(currencySymbol, currency_symbol)
+ rangeGetter(currencyDisplayName, currency_display_name)
+ rangeGetter(currencyFormat, currency_format)
+ rangeGetter(currencyFormatNegative, currency_negative_format)
+ rangeGetter(endonymLanguage, language_endonym)
+ rangeGetter(endonymCountry, country_endonym)
+
+#undef rangeGetter
+
public:
quint16 m_language_id, m_script_id, m_country_id;