utility to recompute the largest unicode range without any characters use to recompute the gap in the global _UNICODE_RANGES of completer.py
()
| 57 | |
| 58 | |
| 59 | def recompute_unicode_ranges(): |
| 60 | """ |
| 61 | utility to recompute the largest unicode range without any characters |
| 62 | |
| 63 | use to recompute the gap in the global _UNICODE_RANGES of completer.py |
| 64 | """ |
| 65 | import itertools |
| 66 | import unicodedata |
| 67 | |
| 68 | valid = [] |
| 69 | for c in range(0, 0x10FFFF + 1): |
| 70 | try: |
| 71 | unicodedata.name(chr(c)) |
| 72 | except ValueError: |
| 73 | continue |
| 74 | valid.append(c) |
| 75 | |
| 76 | def ranges(i): |
| 77 | for a, b in itertools.groupby(enumerate(i), lambda pair: pair[1] - pair[0]): |
| 78 | b = list(b) |
| 79 | yield b[0][1], b[-1][1] |
| 80 | |
| 81 | rg = list(ranges(valid)) |
| 82 | lens = [] |
| 83 | gap_lens = [] |
| 84 | _pstart, pstop = 0, 0 |
| 85 | for start, stop in rg: |
| 86 | lens.append(stop - start) |
| 87 | gap_lens.append( |
| 88 | ( |
| 89 | start - pstop, |
| 90 | hex(pstop + 1), |
| 91 | hex(start), |
| 92 | f"{round((start - pstop)/0xe01f0*100)}%", |
| 93 | ) |
| 94 | ) |
| 95 | _pstart, pstop = start, stop |
| 96 | |
| 97 | return sorted(gap_lens)[-1] |
| 98 | |
| 99 | |
| 100 | def test_unicode_range(): |
no test coverage detected
searching dependent graphs…