MCPcopy Index your code
hub / github.com/python/cpython / DecodeMapWriter

Class DecodeMapWriter

Tools/unicode/genmap_support.py:44–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42
43
44class DecodeMapWriter:
45 filler_class = BufferedFiller
46
47 def __init__(self, fp, prefix, decode_map):
48 self.fp = fp
49 self.prefix = prefix
50 self.decode_map = decode_map
51 self.filler = self.filler_class()
52
53 def update_decode_map(self, c1range, c2range, onlymask=(), wide=0):
54 c2values = range(c2range[0], c2range[1] + 1)
55
56 for c1 in range(c1range[0], c1range[1] + 1):
57 if c1 not in self.decode_map or (onlymask and c1 not in onlymask):
58 continue
59 c2map = self.decode_map[c1]
60 rc2values = [n for n in c2values if n in c2map]
61 if not rc2values:
62 continue
63
64 c2map[self.prefix] = True
65 c2map['min'] = rc2values[0]
66 c2map['max'] = rc2values[-1]
67 c2map['midx'] = len(self.filler)
68
69 for v in range(rc2values[0], rc2values[-1] + 1):
70 if v in c2map:
71 self.filler.write('%d,' % c2map[v])
72 else:
73 self.filler.write('U,')
74
75 def generate(self, wide=False):
76 if not wide:
77 self.fp.write(f"static const ucs2_t __{self.prefix}_decmap[{len(self.filler)}] = {{\n")
78 else:
79 self.fp.write(f"static const Py_UCS4 __{self.prefix}_decmap[{len(self.filler)}] = {{\n")
80
81 self.filler.printout(self.fp)
82 self.fp.write("};\n\n")
83
84 if not wide:
85 self.fp.write(f"static const struct dbcs_index {self.prefix}_decmap[256] = {{\n")
86 else:
87 self.fp.write(f"static const struct widedbcs_index {self.prefix}_decmap[256] = {{\n")
88
89 for i in range(256):
90 if i in self.decode_map and self.prefix in self.decode_map[i]:
91 m = self.decode_map
92 prefix = self.prefix
93 else:
94 self.filler.write("{", "0,", "0,", "0", "},")
95 continue
96
97 self.filler.write("{", "__%s_decmap" % prefix, "+", "%d" % m[i]['midx'],
98 ",", "%d," % m[i]['min'], "%d" % m[i]['max'], "},")
99 self.filler.printout(self.fp)
100 self.fp.write("};\n\n")
101

Callers 5

mainFunction · 0.85
mainFunction · 0.85
write_big5_mapsFunction · 0.85
main_hkscsFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…