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

Function make_hkscs_map

Tools/unicode/genmap_tchinese.py:61–100  ·  view source on GitHub ↗
(table)

Source from the content-addressed store, hash-verified

59
60
61def make_hkscs_map(table):
62 decode_map = {}
63 encode_map_bmp, encode_map_notbmp = {}, {}
64 is_bmp_map = {}
65 sequences = []
66 beginnings = {}
67 single_cp_table = []
68 # Determine multi-codepoint sequences, and sequence beginnings that encode
69 # multiple multibyte (i.e. Big-5) codes.
70 for mbcode, cp_seq in table:
71 cp, *_ = cp_seq
72 if len(cp_seq) == 1:
73 single_cp_table.append((mbcode, cp))
74 else:
75 sequences.append((mbcode, cp_seq))
76 beginnings.setdefault(cp, []).append(mbcode)
77 # Decode table only cares about single code points (no sequences) currently
78 for mbcode, cp in single_cp_table:
79 b1, b2 = split_bytes(mbcode)
80 decode_map.setdefault(b1, {})
81 decode_map[b1][b2] = cp & 0xffff
82 # Encode table needs to mark code points beginning a sequence as tuples.
83 for cp, mbcodes in beginnings.items():
84 plane = cp >> 16
85 if plane == 0:
86 encode_map = encode_map_bmp
87 elif plane == 2:
88 encode_map = encode_map_notbmp
89 is_bmp_map[bh2s(mbcodes[0])] = 1
90 else:
91 assert False, 'only plane 0 (BMP) and plane 2 (SIP) allowed'
92 if len(mbcodes) == 1:
93 encode_value = mbcodes[0]
94 else:
95 encode_value = tuple(mbcodes)
96 uni_b1, uni_b2 = split_bytes(cp & 0xffff)
97 encode_map.setdefault(uni_b1, {})
98 encode_map[uni_b1][uni_b2] = encode_value
99
100 return decode_map, encode_map_bmp, encode_map_notbmp, is_bmp_map
101
102
103def load_big5_map():

Callers 1

main_hkscsFunction · 0.85

Calls 5

split_bytesFunction · 0.85
bh2sFunction · 0.85
appendMethod · 0.45
setdefaultMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…