Return the Unicode block name for ch, or None if ch has no block.
(ch)
| 447 | |
| 448 | |
| 449 | def unicode_block(ch): |
| 450 | '''Return the Unicode block name for ch, or None if ch has no block.''' |
| 451 | cp = ord(ch) |
| 452 | # special case basic latin |
| 453 | if cp <= 0x7F: |
| 454 | return UNICODE_BASIC_LATIN |
| 455 | # binary search for the correct block |
| 456 | be, en = 0, NUM_BLOCKS - 1 |
| 457 | while be <= en: |
| 458 | mid = (be+en) >> 1 |
| 459 | name, start, end = _unicode_blocks[mid] |
| 460 | if start <= cp <= end: |
| 461 | return name |
| 462 | if cp < start: |
| 463 | en = mid-1 |
| 464 | else: |
| 465 | be = mid+1 |
no outgoing calls
no test coverage detected
searching dependent graphs…