diff options
| author | 2022-06-07 14:19:29 +0000 | |
|---|---|---|
| committer | 2022-06-07 14:19:29 +0000 | |
| commit | 5344f27f2bdea8cd33da83c2b289d5a8f845ced7 (patch) | |
| tree | 90cf18008f1dad55e6bdbe9094e518d8b23136bc | |
| parent | e3f5ddc92bb0b2862f152615185bdb5007556a44 (diff) | |
| parent | 6f701fe9fb3e26ffe22da909f6362b53516dd7b4 (diff) | |
Merge "Use python 3 in ./tools/localedata/extract_icu_data.py" am: 6f701fe9fb
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2117508
Change-Id: I9f97d3bf1281b3622faf722d655ae1d0f2eb4698
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rwxr-xr-x | tools/localedata/extract_icu_data.py | 68 |
1 files changed, 34 insertions, 34 deletions
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<uint32_t, uint8_t> LIKELY_SCRIPTS({' + print() + print('const std::unordered_map<uint32_t, uint8_t> 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<uint64_t> REPRESENTATIVE_LOCALES({' + print() + print('std::unordered_set<uint64_t> 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<uint32_t, uint32_t> %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 - - print 'const struct {' - print ' const char script[4];' - print ' const std::unordered_map<uint32_t, uint32_t>* map;' - print '} SCRIPT_PARENTS[] = {' + parent.replace('_', '-'))) + print('});') + print() + + print('const struct {') + print(' const char script[4];') + print(' const std::unordered_map<uint32_t, uint32_t>* 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) |