Skip to content

Commit eab351e

Browse files
committed
Cleanup unicode.py
The methods related to char width are dead code since 464cdff; remove them.
1 parent 191ff2d commit eab351e

File tree

1 file changed

+0
-115
lines changed

1 file changed

+0
-115
lines changed

src/etc/unicode.py

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -271,43 +271,6 @@ def load_properties(f, interestingprops):
271271

272272
return props
273273

274-
# load all widths of want_widths, except those in except_cats
275-
def load_east_asian_width(want_widths, except_cats):
276-
f = "EastAsianWidth.txt"
277-
fetch(f)
278-
widths = {}
279-
re1 = re.compile("^([0-9A-F]+);(\w+) +# (\w+)")
280-
re2 = re.compile("^([0-9A-F]+)\.\.([0-9A-F]+);(\w+) +# (\w+)")
281-
282-
for line in fileinput.input(f):
283-
width = None
284-
d_lo = 0
285-
d_hi = 0
286-
cat = None
287-
m = re1.match(line)
288-
if m:
289-
d_lo = m.group(1)
290-
d_hi = m.group(1)
291-
width = m.group(2)
292-
cat = m.group(3)
293-
else:
294-
m = re2.match(line)
295-
if m:
296-
d_lo = m.group(1)
297-
d_hi = m.group(2)
298-
width = m.group(3)
299-
cat = m.group(4)
300-
else:
301-
continue
302-
if cat in except_cats or width not in want_widths:
303-
continue
304-
d_lo = int(d_lo, 16)
305-
d_hi = int(d_hi, 16)
306-
if width not in widths:
307-
widths[width] = []
308-
widths[width].append((d_lo, d_hi))
309-
return widths
310-
311274
def escape_char(c):
312275
return "'\\u{%x}'" % c if c != 0 else "'\\0'"
313276

@@ -398,47 +361,6 @@ def emit_conversions_module(f, to_upper, to_lower, to_title):
398361
is_pub=False, t_type = t_type, pfun=pfun)
399362
f.write("}\n\n")
400363

401-
def emit_charwidth_module(f, width_table):
402-
f.write("pub mod charwidth {\n")
403-
f.write(" use core::option::Option;\n")
404-
f.write(" use core::option::Option::{Some, None};\n")
405-
f.write(" use core::result::Result::{Ok, Err};\n")
406-
f.write("""
407-
fn bsearch_range_value_table(c: char, is_cjk: bool, r: &'static [(char, char, u8, u8)]) -> u8 {
408-
use core::cmp::Ordering::{Equal, Less, Greater};
409-
match r.binary_search_by(|&(lo, hi, _, _)| {
410-
if lo <= c && c <= hi { Equal }
411-
else if hi < c { Less }
412-
else { Greater }
413-
}) {
414-
Ok(idx) => {
415-
let (_, _, r_ncjk, r_cjk) = r[idx];
416-
if is_cjk { r_cjk } else { r_ncjk }
417-
}
418-
Err(_) => 1
419-
}
420-
}
421-
""")
422-
423-
f.write("""
424-
pub fn width(c: char, is_cjk: bool) -> Option<usize> {
425-
match c as usize {
426-
_c @ 0 => Some(0), // null is zero width
427-
cu if cu < 0x20 => None, // control sequences have no width
428-
cu if cu < 0x7F => Some(1), // ASCII
429-
cu if cu < 0xA0 => None, // more control sequences
430-
_ => Some(bsearch_range_value_table(c, is_cjk, charwidth_table) as usize)
431-
}
432-
}
433-
434-
""")
435-
436-
f.write(" // character width table. Based on Markus Kuhn's free wcwidth() implementation,\n")
437-
f.write(" // http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c\n")
438-
emit_table(f, "charwidth_table", width_table, "&'static [(char, char, u8, u8)]", is_pub=False,
439-
pfun=lambda x: "(%s,%s,%s,%s)" % (escape_char(x[0]), escape_char(x[1]), x[2], x[3]))
440-
f.write("}\n\n")
441-
442364
def emit_norm_module(f, canon, compat, combine, norm_props):
443365
canon_keys = canon.keys()
444366
canon_keys.sort()
@@ -459,43 +381,6 @@ def emit_norm_module(f, canon, compat, combine, norm_props):
459381
canon_comp_keys = canon_comp.keys()
460382
canon_comp_keys.sort()
461383

462-
def remove_from_wtable(wtable, val):
463-
wtable_out = []
464-
while wtable:
465-
if wtable[0][1] < val:
466-
wtable_out.append(wtable.pop(0))
467-
elif wtable[0][0] > val:
468-
break
469-
else:
470-
(wt_lo, wt_hi, width, width_cjk) = wtable.pop(0)
471-
if wt_lo == wt_hi == val:
472-
continue
473-
elif wt_lo == val:
474-
wtable_out.append((wt_lo+1, wt_hi, width, width_cjk))
475-
elif wt_hi == val:
476-
wtable_out.append((wt_lo, wt_hi-1, width, width_cjk))
477-
else:
478-
wtable_out.append((wt_lo, val-1, width, width_cjk))
479-
wtable_out.append((val+1, wt_hi, width, width_cjk))
480-
if wtable:
481-
wtable_out.extend(wtable)
482-
return wtable_out
483-
484-
485-
486-
def optimize_width_table(wtable):
487-
wtable_out = []
488-
w_this = wtable.pop(0)
489-
while wtable:
490-
if w_this[1] == wtable[0][0] - 1 and w_this[2:3] == wtable[0][2:3]:
491-
w_tmp = wtable.pop(0)
492-
w_this = (w_this[0], w_tmp[1], w_tmp[2], w_tmp[3])
493-
else:
494-
wtable_out.append(w_this)
495-
w_this = wtable.pop(0)
496-
wtable_out.append(w_this)
497-
return wtable_out
498-
499384
if __name__ == "__main__":
500385
r = "tables.rs"
501386
if os.path.exists(r):

0 commit comments

Comments
 (0)