(out_dir)
| 117 | |
| 118 | |
| 119 | def 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 | |
| 152 | def main(): |
no test coverage detected