From d0b784fa8a81da6ea06d65eda9550c93dff2f309 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sun, 4 Aug 2019 19:27:41 +0000 Subject: [PATCH] implement imperial table generator Signed-off-by: Ivailo Monev --- scripts/genlocale.py | 39 +++++++++++++++++++++++++++++++++------ src/core/tools/qlocale.cpp | 5 ++--- src/core/tools/qlocale_data_p.h | 30 +++++++++++++----------------- 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/scripts/genlocale.py b/scripts/genlocale.py index 9fd243c42..b609b1167 100755 --- a/scripts/genlocale.py +++ b/scripts/genlocale.py @@ -305,6 +305,8 @@ languagemap = {} countrymap = {} scriptmap = {} localemap = {} +# main lists +imperiallist = [] # cross-reference maps localescriptmap = {} localefirstdaymap = {} @@ -323,10 +325,10 @@ scriptmap['AnyScript'] = ['', 'Default'] # locale to script parsing tree = ET.parse('common/supplemental/supplementalData.xml') root = tree.getroot() -for supllanguage in root.findall('./languageData/language'): - supllanguagetype = supllanguage.get('type') - supllanguagescripts = supllanguage.get('scripts') - localescriptmap[supllanguagetype] = supllanguagescripts +for suppllanguage in root.findall('./languageData/language'): + suppllanguagetype = suppllanguage.get('type') + suppllanguagescripts = suppllanguage.get('scripts') + localescriptmap[suppllanguagetype] = suppllanguagescripts # locale to first day parsing for firstday in root.findall('./weekData/firstDay'): @@ -525,7 +527,7 @@ for xml in glob.glob('common/main/*.xml'): if defaultnumbersystem is not None: numbertype = defaultnumbersystem.text - # find values from suplemental maps + # find values from supplemental maps if langtype: for key in scriptmap.keys(): if localescriptmap[langtype] == scriptmap[key][0]: @@ -796,4 +798,29 @@ for key in sorted(localemap.keys()): printlocaledata(localemap, key) print('};') -print('static const qint16 localeTblSize = sizeof(localeTbl) / sizeof(QLocalePrivate);') +print('static const qint16 localeTblSize = sizeof(localeTbl) / sizeof(QLocalePrivate);\n') + +# imperial parsing +tree = ET.parse('common/supplemental/supplementalData.xml') +root = tree.getroot() +for measurementsystem in root.findall('./measurementData/measurementSystem'): + measurementsystemtype = measurementsystem.get('type') + if measurementsystemtype in ('UK', 'US'): + territories = measurementsystem.get('territories') + for territory in territories.split(' '): + countryenum = None + languageenum = None + for key in countrymap.keys(): + countrycode = countrymap[key][0] + if countrycode == territory: + countryenum = key + break + imperiallist.append(countryenum) + +print('''static const QLocale::Country imperialTbl[] = {''') + +for string in sorted(imperiallist): + print(' QLocale::Country::%s,' % string) + +print('};') +print('static const qint16 imperialTblSize = sizeof(imperialTbl);') \ No newline at end of file diff --git a/src/core/tools/qlocale.cpp b/src/core/tools/qlocale.cpp index 3602bbdfd..3de12f6b7 100644 --- a/src/core/tools/qlocale.cpp +++ b/src/core/tools/qlocale.cpp @@ -1923,9 +1923,8 @@ Qt::DayOfWeek QLocale::firstDayOfWeek() const QLocale::MeasurementSystem QLocalePrivate::measurementSystem() const { - for (int i = 0; i < ImperialMeasurementSystemsCount; ++i) { - if (ImperialMeasurementSystems[i].languageId == m_language - && ImperialMeasurementSystems[i].countryId == m_country) { + for (int i = 0; i < imperialTblSize; ++i) { + if (imperialTbl[i] == m_country) { return QLocale::ImperialSystem; } } diff --git a/src/core/tools/qlocale_data_p.h b/src/core/tools/qlocale_data_p.h index 9a0c6b636..6fe0f6605 100644 --- a/src/core/tools/qlocale_data_p.h +++ b/src/core/tools/qlocale_data_p.h @@ -47,23 +47,6 @@ QT_BEGIN_NAMESPACE -/* This part of the file isn't generated, but written by hand since - * Unicode CLDR doesn't contain measurement system information. - */ -struct CountryLanguage -{ - const quint16 languageId; - const quint16 countryId; -}; -static const CountryLanguage ImperialMeasurementSystems[] = { - { 31, 225 }, - { 31, 226 }, - { 111, 225 }, - { 163, 225 } -}; -static const short ImperialMeasurementSystemsCount = - sizeof(ImperialMeasurementSystems)/sizeof(ImperialMeasurementSystems[0]); - /* This part of the file was generated from Common Locale Data Repository v35 @@ -27039,6 +27022,19 @@ static const QLocalePrivate localeTbl[] = { }; static const qint16 localeTblSize = sizeof(localeTbl) / sizeof(QLocalePrivate); +static const QLocale::Country imperialTbl[] = { + QLocale::Country::Bahamas, + QLocale::Country::Belize, + QLocale::Country::CaymanIslands, + QLocale::Country::Liberia, + QLocale::Country::MyanmarBurma, + QLocale::Country::Palau, + QLocale::Country::PuertoRico, + QLocale::Country::UnitedKingdom, + QLocale::Country::UnitedStates, +}; +static const qint16 imperialTblSize = sizeof(imperialTbl); + // GENERATED PART ENDS HERE QT_END_NAMESPACE -- 2.11.0