MCPcopy Create free account
hub / github.com/alibaba/MNN / write_cpp

Function write_cpp

tools/script/gen_unicode_data.py:119–149  ·  view source on GitHub ↗
(out_dir)

Source from the content-addressed store, hash-verified

117
118
119def write_cpp(out_dir):
120 print(" generating category ranges...")
121 cat_ranges = get_category_ranges()
122 print(f" {len(cat_ranges)} ranges")
123
124 print(" generating toLower map...")
125 tolower = get_tolower_map()
126 print(f" {len(tolower)} entries")
127
128 path = os.path.join(out_dir, "unicode_data.cpp")
129 with open(path, 'w') as f:
130 f.write("// Auto-generated by gen_unicode_data.py - DO NOT EDIT\n")
131 f.write('#include "unicode_data.hpp"\n\n')
132 f.write("namespace MNN {\nnamespace Unicode {\n\n")
133
134 # Category ranges
135 f.write(f"const CategoryRange kCategoryRanges[] = {{\n")
136 for start, end, cat in cat_ranges:
137 f.write(f" {{0x{start:X}, 0x{end:X}, {cat}}},\n")
138 f.write("};\n")
139 f.write(f"const size_t kCategoryRangesSize = {len(cat_ranges)};\n\n")
140
141 # toLower
142 f.write(f"const CaseMapping kToLower[] = {{\n")
143 for frm, to in tolower:
144 f.write(f" {{0x{frm:X}, 0x{to:X}}},\n")
145 f.write("};\n")
146 f.write(f"const size_t kToLowerSize = {len(tolower)};\n\n")
147
148 f.write("} // namespace Unicode\n} // namespace MNN\n")
149 print(f" wrote {path}")
150
151
152def main():

Callers 1

mainFunction · 0.85

Calls 6

printFunction · 0.85
get_category_rangesFunction · 0.85
get_tolower_mapFunction · 0.85
openFunction · 0.85
joinMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected