Skip to content

Commit 8f0c9e7

Browse files
committed
separate range accumulation from range output
It's easier to merge identical mapping entries if we have a separate representation of all the ranges we're going to print out.
1 parent d19d5d0 commit 8f0c9e7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

idna/src/make_uts46_mapping_table.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def strtab_slice(s):
5353
def rust_slice(s):
5454
return "(StringTableSlice { byte_start: %d, byte_len: %d })" % s
5555

56+
ranges = []
57+
5658
for line in txt:
5759
# remove comments
5860
line, _, _ = line.partition('#')
@@ -66,12 +68,17 @@ def rust_slice(s):
6668
if not last:
6769
last = first
6870
mapping = fields[1].strip().replace('_', ' ').title().replace(' ', '')
71+
unicode_str = None
6972
if len(fields) > 2:
7073
if fields[2].strip():
7174
unicode_str = u''.join(char(c) for c in fields[2].strip().split(' '))
72-
mapping += rust_slice(strtab_slice(unicode_str))
7375
elif mapping == "Deviation":
74-
mapping += rust_slice(strtab_slice(''))
76+
unicode_str = u''
77+
ranges.append((first, last, mapping, unicode_str))
78+
79+
for (first, last, mapping, unicode_str) in ranges:
80+
if unicode_str is not None:
81+
mapping += rust_slice(strtab_slice(unicode_str))
7582
print(" Range { from: '%s', to: '%s', mapping: %s }," % (escape_char(char(first)),
7683
escape_char(char(last)),
7784
mapping))

0 commit comments

Comments
 (0)