OSDN Git Service

implement imperial table generator
authorIvailo Monev <xakepa10@laimg.moc>
Sun, 4 Aug 2019 19:27:41 +0000 (19:27 +0000)
committerIvailo Monev <xakepa10@laimg.moc>
Sun, 4 Aug 2019 19:27:41 +0000 (19:27 +0000)
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
scripts/genlocale.py
src/core/tools/qlocale.cpp
src/core/tools/qlocale_data_p.h

index 9fd243c..b609b11 100755 (executable)
@@ -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
index 3602bbd..3de12f6 100644 (file)
@@ -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;
         }
     }
index 9a0c6b6..6fe0f66 100644 (file)
 
 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