| 23 | |
| 24 | |
| 25 | def make_width_table() -> Iterable[Tuple[int, int, int]]: |
| 26 | start_codepoint = -1 |
| 27 | end_codepoint = -1 |
| 28 | range_width = -2 |
| 29 | for codepoint in range(0, sys.maxunicode + 1): |
| 30 | width = wcwidth.wcwidth(chr(codepoint)) |
| 31 | if width <= 1: |
| 32 | # Ignore narrow characters along with zero-width characters so that |
| 33 | # they are treated as single-width. Note that treating zero-width |
| 34 | # characters as single-width is consistent with the heuristics built |
| 35 | # on top of str.isascii() in the str_width() function in strings.py. |
| 36 | continue |
| 37 | if start_codepoint < 0: |
| 38 | start_codepoint = codepoint |
| 39 | range_width = width |
| 40 | elif width != range_width or codepoint != end_codepoint + 1: |
| 41 | yield (start_codepoint, end_codepoint, range_width) |
| 42 | start_codepoint = codepoint |
| 43 | range_width = width |
| 44 | end_codepoint = codepoint |
| 45 | if start_codepoint >= 0: |
| 46 | yield (start_codepoint, end_codepoint, range_width) |
| 47 | |
| 48 | |
| 49 | def main() -> None: |