implement imperial table generator

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
Ivailo Monev 2019-08-04 19:27:41 +00:00
parent 4d06a1b9ca
commit d0b784fa8a
3 changed files with 48 additions and 26 deletions

View file

@ -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);')

View 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;
}
}

View file

@ -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