diff --git a/tools/localedata/extract_icu_data.py b/tools/localedata/extract_icu_data.py index ca1847af7d06..81ac897deae0 100755 --- a/tools/localedata/extract_icu_data.py +++ b/tools/localedata/extract_icu_data.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Copyright 2016 The Android Open Source Project. All Rights Reserved. # @@ -61,7 +61,7 @@ def read_likely_subtags(input_file_name): # would be chosen.) } for line in input_file: - line = unicode(line, 'UTF-8').strip(u' \n\uFEFF').encode('UTF-8') + line = line.strip(u' \n\uFEFF') if line.startswith('//'): continue if '{' in line and '}' in line: @@ -118,26 +118,26 @@ def pack_to_uint32(locale): def dump_script_codes(all_scripts): """Dump the SCRIPT_CODES table.""" - print 'const char SCRIPT_CODES[][4] = {' + print('const char SCRIPT_CODES[][4] = {') for index, script in enumerate(all_scripts): - print " /* %-2d */ {'%c', '%c', '%c', '%c'}," % ( - index, script[0], script[1], script[2], script[3]) - print '};' - print + print(" /* %-2d */ {'%c', '%c', '%c', '%c'}," % ( + index, script[0], script[1], script[2], script[3])) + print('};') + print() def dump_script_data(likely_script_dict, all_scripts): """Dump the script data.""" - print - print 'const std::unordered_map LIKELY_SCRIPTS({' + print() + print('const std::unordered_map LIKELY_SCRIPTS({') for locale in sorted(likely_script_dict.keys()): script = likely_script_dict[locale] - print ' {0x%08Xu, %2du}, // %s -> %s' % ( + print(' {0x%08Xu, %2du}, // %s -> %s' % ( pack_to_uint32(locale), all_scripts.index(script), locale.replace('_', '-'), - script) - print '});' + script)) + print('});') def pack_to_uint64(locale): @@ -152,13 +152,13 @@ def pack_to_uint64(locale): def dump_representative_locales(representative_locales): """Dump the set of representative locales.""" - print - print 'std::unordered_set REPRESENTATIVE_LOCALES({' + print() + print('std::unordered_set REPRESENTATIVE_LOCALES({') for locale in sorted(representative_locales): - print ' 0x%08XLLU, // %s' % ( + print(' 0x%08XLLU, // %s' % ( pack_to_uint64(locale), - locale) - print '});' + locale)) + print('});') def read_and_dump_likely_data(icu_data_dir): @@ -220,30 +220,30 @@ def get_likely_script(locale, likely_script_dict): def dump_parent_data(script_organized_dict): """Dump information for parents of locales.""" sorted_scripts = sorted(script_organized_dict.keys()) - print + print() for script in sorted_scripts: parent_dict = script_organized_dict[script] print ('const std::unordered_map %s_PARENTS({' % escape_script_variable_name(script.upper())) for locale in sorted(parent_dict.keys()): parent = parent_dict[locale] - print ' {0x%08Xu, 0x%08Xu}, // %s -> %s' % ( + print(' {0x%08Xu, 0x%08Xu}, // %s -> %s' % ( pack_to_uint32(locale), pack_to_uint32(parent), locale.replace('_', '-'), - parent.replace('_', '-')) - print '});' - print + parent.replace('_', '-'))) + print('});') + print() - print 'const struct {' - print ' const char script[4];' - print ' const std::unordered_map* map;' - print '} SCRIPT_PARENTS[] = {' + print('const struct {') + print(' const char script[4];') + print(' const std::unordered_map* map;') + print('} SCRIPT_PARENTS[] = {') for script in sorted_scripts: - print " {{'%c', '%c', '%c', '%c'}, &%s_PARENTS}," % ( + print(" {{'%c', '%c', '%c', '%c'}, &%s_PARENTS}," % ( script[0], script[1], script[2], script[3], - escape_script_variable_name(script.upper())) - print '};' + escape_script_variable_name(script.upper()))) + print('};') def dump_parent_tree_depth(parent_dict): @@ -256,8 +256,8 @@ def dump_parent_tree_depth(parent_dict): depth += 1 max_depth = max(max_depth, depth) assert max_depth < 5 # Our algorithms assume small max_depth - print - print 'const size_t MAX_PARENT_DEPTH = %d;' % max_depth + print() + print('const size_t MAX_PARENT_DEPTH = %d;' % max_depth) def read_and_dump_parent_data(icu_data_dir, likely_script_dict): @@ -281,8 +281,8 @@ def main(): source_root, 'external', 'icu', 'icu4c', 'source', 'data') - print '// Auto-generated by %s' % sys.argv[0] - print + print('// Auto-generated by %s' % sys.argv[0]) + print() likely_script_dict = read_and_dump_likely_data(icu_data_dir) read_and_dump_parent_data(icu_data_dir, likely_script_dict)