| 1016 | # load a unicode-data file from disk |
| 1017 | |
| 1018 | class UnicodeData: |
| 1019 | # table: List[Optional[UcdRecord]] # index is codepoint; None means unassigned |
| 1020 | |
| 1021 | def __init__(self, version, ideograph_check=True): |
| 1022 | self.changed = [] |
| 1023 | table = [None] * 0x110000 |
| 1024 | for s in UcdFile(UNICODE_DATA, version): |
| 1025 | char = int(s[0], 16) |
| 1026 | table[char] = from_row(s) |
| 1027 | |
| 1028 | self.derived_name_ranges = [] |
| 1029 | self.derived_name_prefixes = { |
| 1030 | prefix: i |
| 1031 | for i, (_, prefix) in enumerate(derived_name_range_names) |
| 1032 | } |
| 1033 | |
| 1034 | # expand first-last ranges |
| 1035 | field = None |
| 1036 | for i in range(0, 0x110000): |
| 1037 | # The file UnicodeData.txt has its own distinct way of |
| 1038 | # expressing ranges. See: |
| 1039 | # https://www.unicode.org/reports/tr44/#Code_Point_Ranges |
| 1040 | s = table[i] |
| 1041 | if s: |
| 1042 | if s.name[-6:] == "First>": |
| 1043 | s.name = "" |
| 1044 | field = dataclasses.astuple(s)[:15] |
| 1045 | elif s.name[-5:] == "Last>": |
| 1046 | for j, (rangename, _) in enumerate(derived_name_range_names): |
| 1047 | if s.name.startswith("<" + rangename): |
| 1048 | self.derived_name_ranges.append( |
| 1049 | (field[0], s.codepoint, j)) |
| 1050 | break |
| 1051 | s.name = "" |
| 1052 | field = None |
| 1053 | else: |
| 1054 | codepoint = s.codepoint |
| 1055 | if s.name.endswith(codepoint): |
| 1056 | prefix = s.name[:-len(codepoint)] |
| 1057 | j = self.derived_name_prefixes.get(prefix) |
| 1058 | if j is None: |
| 1059 | j = len(self.derived_name_prefixes) |
| 1060 | self.derived_name_prefixes[prefix] = j |
| 1061 | if (self.derived_name_ranges |
| 1062 | and self.derived_name_ranges[-1][2] == j |
| 1063 | and int(self.derived_name_ranges[-1][1], 16) == i - 1): |
| 1064 | self.derived_name_ranges[-1][1] = codepoint |
| 1065 | else: |
| 1066 | self.derived_name_ranges.append( |
| 1067 | [codepoint, codepoint, j]) |
| 1068 | s.name = "" |
| 1069 | elif field: |
| 1070 | table[i] = from_row(('%04X' % i,) + field[1:]) |
| 1071 | |
| 1072 | # public attributes |
| 1073 | self.filename = UNICODE_DATA % '' |
| 1074 | self.table = table |
| 1075 | self.chars = list(range(0x110000)) # unicode 3.2 |
no outgoing calls
no test coverage detected
searching dependent graphs…