| 33 | |
| 34 | |
| 35 | def show_char_table(chars: str, byte_min: int = 0, byte_max: int = 0xFF) -> None: |
| 36 | char_data: list[CharData] = [] |
| 37 | for char in chars: |
| 38 | name = unicodedata.name(char, "<unknown>") |
| 39 | codept = ord(char) |
| 40 | encodings: list[tuple[str, int]] = [] |
| 41 | for encoding in SAFE_ENCODINGS: |
| 42 | try: |
| 43 | encoded: bytes = char.encode(encoding) |
| 44 | byte: int = encoded[0] |
| 45 | encodings.append((encoding, byte)) |
| 46 | except UnicodeEncodeError: |
| 47 | pass |
| 48 | if encodings: |
| 49 | char_data.append(CharData(name=name, codept=codept, encodings=encodings)) |
| 50 | else: |
| 51 | print(f"No relevant encoding for {codept=}, {name=}") |
| 52 | char_data.sort(key=CharData.sort_key) |
| 53 | for cd in char_data: |
| 54 | encoding_info: list[str] = [] |
| 55 | for encoding, byte in cd.encodings: |
| 56 | if byte_min <= byte <= byte_max: |
| 57 | info_str = f"{encoding}:{byte:X}" |
| 58 | encoding_info.append(info_str) |
| 59 | if encoding_info: |
| 60 | encoding_explanation = encoding_info[0] |
| 61 | else: |
| 62 | encoding_explanation = "???" |
| 63 | print(f' "\\N{{{cd.name}}}" # {encoding_explanation}') |
| 64 | |
| 65 | |
| 66 | def run() -> None: |