-
Notifications
You must be signed in to change notification settings - Fork 25
/
confusable.nim
60 lines (46 loc) · 1.39 KB
/
confusable.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import strutils, strfmt, algorithm
var mappings: array[0x80, seq[int]]
var confusables: array[0x80, seq[int]]
for line in "confusables.txt".lines:
let fields = line.split(" ;\t")
if fields.len < 3 or not fields[2].startsWith("MA"):
continue
var smaller = fields[0].parseHexInt
if fields[1].count(' ') > 0:
var s = fields[1].split(' ').map(parseHexInt)
if smaller < 0x80:
mappings[smaller] = s
for line in "confusables.txt".lines:
let fields = line.split(" ;\t")
if fields.len < 3 or not fields[2].startsWith("MA"):
continue
var smaller = fields[0].parseHexInt
var bigger: int
block outer:
if fields[1].count(' ') > 0:
var s = fields[1].split(' ').map(parseHexInt)
for key, mapping in mappings:
if s == mapping and smaller != key:
bigger = key
break outer
continue
else:
bigger = fields[1].parseHexInt
if bigger < smaller:
swap bigger, smaller
if smaller >= 0x80:
continue
if confusables[smaller].isNil:
confusables[smaller] = @[]
confusables[smaller].add(bigger)
for smaller, confs in confusables.mpairs:
if confs.isNil:
#echo smaller.toHex(4), " ", char(smaller)
continue
stdout.writefmt "\tcase 0x{:04X}: return ", smaller
confs.sort(cmp)
for i, bigger in confs:
if i > 0:
stdout.write " || "
stdout.writefmt "bigger == 0x{:04X}", bigger
stdout.writeln ";"