Reduce code duplication in writing of string data for locales

Each StringData object got its own block, of common form, to output
its C array; give each object a name so that we can automate this as
an iteration over StringData objects.  One (endonyms_data) gains a
blank line that the others all had but it lacked.

Change-Id: I96c014728a58343c82304c5117b474fee980d9c7
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Edward Welbourne 2017-05-31 16:17:54 +02:00
parent ebb0212133
commit 03a1675eac
2 changed files with 24 additions and 87 deletions

View File

@ -77,7 +77,7 @@ static const int ImperialMeasurementSystemsCount =
// GENERATED PART STARTS HERE // GENERATED PART STARTS HERE
/* /*
This part of the file was generated on 2017-05-23 from the This part of the file was generated on 2017-05-31 from the
Common Locale Data Repository v29 Common Locale Data Repository v29
http://www.unicode.org/cldr/ http://www.unicode.org/cldr/
@ -5747,6 +5747,7 @@ static const ushort currency_format_data[] = {
0x31, 0x25, 0x31, 0xa0, 0x6d, 0x6e, 0xa0, 0x25, 0x32, 0x25, 0x32, 0xa0, 0x25, 0x31, 0x2d, 0x25, 0x32, 0xa0, 0x25, 0x31, 0x31, 0x25, 0x31, 0xa0, 0x6d, 0x6e, 0xa0, 0x25, 0x32, 0x25, 0x32, 0xa0, 0x25, 0x31, 0x2d, 0x25, 0x32, 0xa0, 0x25, 0x31,
0x4b, 0x200e, 0x25, 0x32, 0x25, 0x31, 0x28, 0x25, 0x32, 0x25, 0x31, 0x29, 0x25, 0x32, 0x2d, 0xa0, 0x25, 0x31 0x4b, 0x200e, 0x25, 0x32, 0x25, 0x31, 0x28, 0x25, 0x32, 0x25, 0x31, 0x29, 0x25, 0x32, 0x2d, 0xa0, 0x25, 0x31
}; };
static const ushort endonyms_data[] = { static const ushort endonyms_data[] = {
0x4f, 0x72, 0x6f, 0x6d, 0x6f, 0x6f, 0x49, 0x74, 0x6f, 0x6f, 0x70, 0x68, 0x69, 0x79, 0x61, 0x61, 0x4b, 0x65, 0x65, 0x6e, 0x4f, 0x72, 0x6f, 0x6d, 0x6f, 0x6f, 0x49, 0x74, 0x6f, 0x6f, 0x70, 0x68, 0x69, 0x79, 0x61, 0x61, 0x4b, 0x65, 0x65, 0x6e,
0x69, 0x79, 0x61, 0x61, 0x41, 0x66, 0x72, 0x69, 0x6b, 0x61, 0x61, 0x6e, 0x73, 0x53, 0x75, 0x69, 0x64, 0x2d, 0x41, 0x66, 0x69, 0x79, 0x61, 0x61, 0x41, 0x66, 0x72, 0x69, 0x6b, 0x61, 0x61, 0x6e, 0x73, 0x53, 0x75, 0x69, 0x64, 0x2d, 0x41, 0x66,

View File

@ -300,9 +300,10 @@ class StringDataToken:
return " %d,%d " % (self.index, self.length) return " %d,%d " % (self.index, self.length)
class StringData: class StringData:
def __init__(self): def __init__(self, name):
self.data = [] self.data = []
self.hash = {} self.hash = {}
self.name = name
def append(self, s): def append(self, s):
if s in self.hash: if s in self.hash:
return self.hash[s] return self.hash[s]
@ -495,17 +496,17 @@ def main():
data_temp_file.write("\n") data_temp_file.write("\n")
list_pattern_part_data = StringData() list_pattern_part_data = StringData('list_pattern_part_data')
date_format_data = StringData() date_format_data = StringData('date_format_data')
time_format_data = StringData() time_format_data = StringData('time_format_data')
months_data = StringData() months_data = StringData('months_data')
days_data = StringData() days_data = StringData('days_data')
am_data = StringData() am_data = StringData('am_data')
pm_data = StringData() pm_data = StringData('pm_data')
currency_symbol_data = StringData() currency_symbol_data = StringData('currency_symbol_data')
currency_display_name_data = StringData() currency_display_name_data = StringData('currency_display_name_data')
currency_format_data = StringData() currency_format_data = StringData('currency_format_data')
endonyms_data = StringData() endonyms_data = StringData('endonyms_data')
# Locale data # Locale data
data_temp_file.write("static const QLocaleData locale_data[] = {\n") data_temp_file.write("static const QLocaleData locale_data[] = {\n")
@ -651,79 +652,14 @@ def main():
+ " // trailing 0s\n") + " // trailing 0s\n")
data_temp_file.write("};\n") data_temp_file.write("};\n")
data_temp_file.write("\n") # StringData tables:
for data in (list_pattern_part_data, date_format_data,
# List patterns data time_format_data, months_data, days_data,
data_temp_file.write("static const ushort list_pattern_part_data[] = {\n") am_data, pm_data, currency_symbol_data,
data_temp_file.write(wrap_list(list_pattern_part_data.data)) currency_display_name_data, currency_format_data,
data_temp_file.write("\n};\n") endonyms_data):
data_temp_file.write("\nstatic const ushort %s[] = {\n" % data.name)
data_temp_file.write("\n") data_temp_file.write(wrap_list(data.data))
# Date format data
data_temp_file.write("static const ushort date_format_data[] = {\n")
data_temp_file.write(wrap_list(date_format_data.data))
data_temp_file.write("\n};\n")
data_temp_file.write("\n")
# Time format data
data_temp_file.write("static const ushort time_format_data[] = {\n")
data_temp_file.write(wrap_list(time_format_data.data))
data_temp_file.write("\n};\n")
data_temp_file.write("\n")
# Months data
data_temp_file.write("static const ushort months_data[] = {\n")
data_temp_file.write(wrap_list(months_data.data))
data_temp_file.write("\n};\n")
data_temp_file.write("\n")
# Days data
data_temp_file.write("static const ushort days_data[] = {\n")
data_temp_file.write(wrap_list(days_data.data))
data_temp_file.write("\n};\n")
data_temp_file.write("\n")
# AM data
data_temp_file.write("static const ushort am_data[] = {\n")
data_temp_file.write(wrap_list(am_data.data))
data_temp_file.write("\n};\n")
data_temp_file.write("\n")
# PM data
data_temp_file.write("static const ushort pm_data[] = {\n")
data_temp_file.write(wrap_list(pm_data.data))
data_temp_file.write("\n};\n")
data_temp_file.write("\n")
# Currency symbol data
data_temp_file.write("static const ushort currency_symbol_data[] = {\n")
data_temp_file.write(wrap_list(currency_symbol_data.data))
data_temp_file.write("\n};\n")
data_temp_file.write("\n")
# Currency display name data
data_temp_file.write("static const ushort currency_display_name_data[] = {\n")
data_temp_file.write(wrap_list(currency_display_name_data.data))
data_temp_file.write("\n};\n")
data_temp_file.write("\n")
# Currency format data
data_temp_file.write("static const ushort currency_format_data[] = {\n")
data_temp_file.write(wrap_list(currency_format_data.data))
data_temp_file.write("\n};\n")
# Endonyms data
data_temp_file.write("static const ushort endonyms_data[] = {\n")
data_temp_file.write(wrap_list(endonyms_data.data))
data_temp_file.write("\n};\n") data_temp_file.write("\n};\n")
data_temp_file.write("\n") data_temp_file.write("\n")