diff options
author | Boris Faure <billiob@gmail.com> | 2020-07-06 19:40:20 +0200 |
---|---|---|
committer | Boris Faure <billiob@gmail.com> | 2020-07-06 19:40:20 +0200 |
commit | 7d1536c8e9fc038b6759062720957c5532480a0f (patch) | |
tree | d625062f6c33d677c5c13f2c7410f1a283139708 | |
parent | 8c970b88047882fe95907c06b08ff31eb2a6cad3 (diff) |
tools/unicode_dbl_width: do not redefine range
-rwxr-xr-x | tools/unicode_dbl_width.py | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/tools/unicode_dbl_width.py b/tools/unicode_dbl_width.py index 2457834..adbd936 100755 --- a/tools/unicode_dbl_width.py +++ b/tools/unicode_dbl_width.py | |||
@@ -10,7 +10,7 @@ import argparse | |||
10 | from collections import namedtuple | 10 | from collections import namedtuple |
11 | import xml.etree.ElementTree as ET | 11 | import xml.etree.ElementTree as ET |
12 | 12 | ||
13 | Range = namedtuple('range', ['width', 'start', 'end']) | 13 | URange = namedtuple('unicode_range', ['width', 'start', 'end']) |
14 | 14 | ||
15 | def get_ranges(xmlfile, emoji_as_wide): | 15 | def get_ranges(xmlfile, emoji_as_wide): |
16 | tree = ET.parse(xmlfile) | 16 | tree = ET.parse(xmlfile) |
@@ -19,14 +19,13 @@ def get_ranges(xmlfile, emoji_as_wide): | |||
19 | chars = repertoire.findall("{http://www.unicode.org/ns/2003/ucd/1.0}char") | 19 | chars = repertoire.findall("{http://www.unicode.org/ns/2003/ucd/1.0}char") |
20 | 20 | ||
21 | ranges = [] | 21 | ranges = [] |
22 | range = Range('N', 0, 0) | 22 | r = URange('N', 0, 0) |
23 | for c in chars: | 23 | for c in chars: |
24 | ea = c.get('ea') | 24 | ea = c.get('ea') |
25 | if ea in ('Na', 'H'): | 25 | if ea in ('Na', 'H'): |
26 | ea = 'N' | 26 | ea = 'N' |
27 | if ea in ('F'): | 27 | if ea in ('F'): |
28 | ea = 'W' | 28 | ea = 'W' |
29 | assert ea in ('N', 'A', 'W') | ||
30 | cp = c.get('cp') | 29 | cp = c.get('cp') |
31 | if not cp: | 30 | if not cp: |
32 | continue | 31 | continue |
@@ -36,26 +35,26 @@ def get_ranges(xmlfile, emoji_as_wide): | |||
36 | ea = 'W' | 35 | ea = 'W' |
37 | 36 | ||
38 | cp = int(cp, 16) | 37 | cp = int(cp, 16) |
39 | if ea != range[0]: | 38 | if ea != r[0]: |
40 | ranges.append(range) | 39 | ranges.append(r) |
41 | range = Range(ea, cp, cp) | 40 | r = URange(ea, cp, cp) |
42 | else: | 41 | else: |
43 | range = range._replace(end=cp) | 42 | r = r._replace(end=cp) |
44 | 43 | ||
45 | ranges.append(range) | 44 | ranges.append(r) |
46 | 45 | ||
47 | return ranges | 46 | return ranges |
48 | 47 | ||
49 | def merge_ranges(ranges, is_same_width): | 48 | def merge_ranges(ranges, is_same_width): |
50 | res = [] | 49 | res = [] |
51 | range = ranges[0] | 50 | cur_range = ranges[0] |
52 | for r in ranges: | 51 | for r in ranges: |
53 | if is_same_width(r, range): | 52 | if is_same_width(r, cur_range): |
54 | range = range._replace(end=r.end) | 53 | cur_range = cur_range._replace(end=r.end) |
55 | else: | 54 | else: |
56 | res.append(range) | 55 | res.append(cur_range) |
57 | range = r | 56 | cur_range = r |
58 | res.append(range) | 57 | res.append(cur_range) |
59 | return res | 58 | return res |
60 | 59 | ||
61 | def skip_ranges(ranges, width_skipped): | 60 | def skip_ranges(ranges, width_skipped): |
@@ -65,7 +64,7 @@ def skip_ranges(ranges, width_skipped): | |||
65 | res.append(r) | 64 | res.append(r) |
66 | return res | 65 | return res |
67 | 66 | ||
68 | def gen_header(range, file_header): | 67 | def gen_header(cur_range, file_header): |
69 | file_header.write( | 68 | file_header.write( |
70 | """/* XXX: Code generated by tool unicode_dbl_width.py */ | 69 | """/* XXX: Code generated by tool unicode_dbl_width.py */ |
71 | #ifndef _TERMPTY_DBL_H__ | 70 | #ifndef _TERMPTY_DBL_H__ |
@@ -79,7 +78,7 @@ _termpty_is_dblwidth_get(const Termpty *ty, const Eina_Unicode g) | |||
79 | { | 78 | { |
80 | /* optimize for latin1 non-ambiguous */ | 79 | /* optimize for latin1 non-ambiguous */ |
81 | """) | 80 | """) |
82 | file_header.write(f" if (g <= 0x{range.end:X})") | 81 | file_header.write(f" if (g <= 0x{cur_range.end:X})") |
83 | file_header.write( | 82 | file_header.write( |
84 | """ | 83 | """ |
85 | return EINA_FALSE; | 84 | return EINA_FALSE; |