(unicode, trace)
| 172 | # unicode character properties |
| 173 | |
| 174 | def makeunicodedata(unicode, trace): |
| 175 | |
| 176 | # the default value of east_asian_width is "N", for unassigned code points |
| 177 | # not mentioned in EastAsianWidth.txt |
| 178 | # in addition there are some reserved but unassigned code points in CJK |
| 179 | # ranges that are classified as "W". code points in private use areas |
| 180 | # have a width of "A". both of these have entries in |
| 181 | # EastAsianWidth.txt |
| 182 | # see https://unicode.org/reports/tr11/#Unassigned |
| 183 | assert EASTASIANWIDTH_NAMES[0] == "N" |
| 184 | assert GRAPHEME_CLUSTER_NAMES[0] == "Other" |
| 185 | assert INDIC_CONJUNCT_BREAK_NAMES[0] == "None" |
| 186 | dummy = (0, 0, 0, 0, 0, 0, 0, 0, 0) |
| 187 | table = [dummy] |
| 188 | cache = {0: dummy} |
| 189 | index = [0] * len(unicode.chars) |
| 190 | |
| 191 | FILE = "Modules/unicodedata_db.h" |
| 192 | |
| 193 | print("--- Preparing", FILE, "...") |
| 194 | |
| 195 | # 1) database properties |
| 196 | |
| 197 | for char in unicode.chars: |
| 198 | record = unicode.table[char] |
| 199 | eastasianwidth = EASTASIANWIDTH_NAMES.index(unicode.widths[char] or 'N') |
| 200 | graphemebreak = GRAPHEME_CLUSTER_NAMES.index(unicode.grapheme_breaks[char] or 'Other') |
| 201 | extpict = unicode.ext_picts[char] |
| 202 | bidirectional = BIDIRECTIONAL_NAMES.index(unicode.bidi_classes[char]) |
| 203 | if record: |
| 204 | # extract database properties |
| 205 | category = CATEGORY_NAMES.index(record.general_category) |
| 206 | combining = int(record.canonical_combining_class) |
| 207 | mirrored = record.bidi_mirrored == "Y" |
| 208 | normalizationquickcheck = record.quick_check |
| 209 | incb = INDIC_CONJUNCT_BREAK_NAMES.index(record.incb) |
| 210 | item = ( |
| 211 | category, combining, bidirectional, mirrored, eastasianwidth, |
| 212 | normalizationquickcheck, graphemebreak, incb, extpict, |
| 213 | ) |
| 214 | else: |
| 215 | if eastasianwidth or graphemebreak or extpict or bidirectional: |
| 216 | item = (0, 0, bidirectional, 0, eastasianwidth, |
| 217 | 0, graphemebreak, 0, extpict) |
| 218 | else: |
| 219 | continue |
| 220 | |
| 221 | # add entry to index and item tables |
| 222 | i = cache.get(item) |
| 223 | if i is None: |
| 224 | cache[item] = i = len(table) |
| 225 | table.append(item) |
| 226 | index[char] = i |
| 227 | |
| 228 | # 2) decomposition data |
| 229 | |
| 230 | decomp_data_cache = {} |
| 231 | decomp_data = [0] |
no test coverage detected
searching dependent graphs…