A file in the standard format of the UCD. See: https://www.unicode.org/reports/tr44/#Format_Conventions Note that, as described there, the Unihan data files have their own separate format.
| 935 | |
| 936 | |
| 937 | class UcdFile: |
| 938 | ''' |
| 939 | A file in the standard format of the UCD. |
| 940 | |
| 941 | See: https://www.unicode.org/reports/tr44/#Format_Conventions |
| 942 | |
| 943 | Note that, as described there, the Unihan data files have their |
| 944 | own separate format. |
| 945 | ''' |
| 946 | |
| 947 | def __init__(self, template: str, version: str) -> None: |
| 948 | self.template = template |
| 949 | self.version = version |
| 950 | |
| 951 | def records(self) -> Iterator[List[str]]: |
| 952 | with open_data(self.template, self.version) as file: |
| 953 | for line in file: |
| 954 | line = line.split('#', 1)[0].strip() |
| 955 | if not line: |
| 956 | continue |
| 957 | yield [field.strip() for field in line.split(';')] |
| 958 | |
| 959 | def __iter__(self) -> Iterator[List[str]]: |
| 960 | return self.records() |
| 961 | |
| 962 | def expanded(self) -> Iterator[Tuple[int, List[str]]]: |
| 963 | for record in self.records(): |
| 964 | char_range, rest = record[0], record[1:] |
| 965 | for char in expand_range(char_range): |
| 966 | yield char, rest |
| 967 | |
| 968 | |
| 969 | @dataclasses.dataclass |
no outgoing calls
no test coverage detected
searching dependent graphs…