phonenumbers.unicode_util | index phonenumbers/unicode_util.py |
Unicode utility functions
>>> from .import unicode_util
>>> from .util import u
>>> u1 = '1' # DIGIT ONE
>>> u2 = u('a') # LATIN SMALL LETTER A
>>> u3 = u('๏ผ') # FULLWIDTH DIGIT TWO
>>> u4 = u('ฤ') # LATIN CAPITAL LETTER A WITH MACRON
>>> unicode_util.Category.get(u1) == u('Nd')
True
>>> unicode_util.Category.get(u2) == u('Ll')
True
>>> unicode_util.Category.get(u3) == u('Nd')
True
>>> unicode_util.Category.get(u4) == u('Lu')
True
>>> unicode_util.Category.get(u2) == unicode_util.Category.LOWERCASE_LETTER
True
>>> try:
... beyond_bmp = u('๐') # AEGEAN WORD SEPARATOR LINE
... except Exception:
... beyond_bmp = u('')
>>> if len(beyond_bmp) == 1: # We have a UCS4 build of Python
... cat_po = unicode_util.Category.get(beyond_bmp)
... else: # UCS2 build of Python; no non-BMP chars available
... cat_po = unicode_util.Category.OTHER_PUNCTUATION
>>> cat_po == u('Po')
True
>>> unicode_util.is_letter(u1)
False
>>> unicode_util.is_letter(u2)
True
>>> unicode_util.is_letter(u3)
False
>>> unicode_util.is_letter(u4)
True
>>> b1 = unicode_util.Block.get(u1)
>>> str(b1)
'Block[0000, 007f]'
>>> b1 == unicode_util.Block.BASIC_LATIN
True
>>> b1 == [0x0000, 0x0075]
False
>>> b2 = unicode_util.Block.get(u2)
>>> b2 == unicode_util.Block.BASIC_LATIN
True
>>> b3 = unicode_util.Block.get(u3)
>>> b3 != unicode_util.Block.BASIC_LATIN
True
>>> b3 == unicode_util.Block.HALFWIDTH_AND_FULLWIDTH_FORMS
True
>>> b4 = unicode_util.Block.get(u4)
>>> b4 == unicode_util.Block.LATIN_EXTENDED_A
True
>>> unicode_util.Block.get(u('เก ')) == unicode_util.Block.UNKNOWN
True
>>> try:
... unknown_block = u('๐ฐ')
... except Exception:
... unknown_block = u('')
>>> if len(unknown_block) == 1: # We have a UCS4 build of Python
... unicode_util.Block.get(u('๐ฐ')) == unicode_util.Block.UNKNOWN
... else: # UCS2 build of Python; no unknown characters available
... True
True
>>> unicode_util.digit(u1)
1
>>> unicode_util.digit(u2, -1)
-1
>>> unicode_util.digit(u3, -1)
2
>>> str(hash(b3)) # doctest: +ELLIPSIS
'...'
Modules | ||||||
|
Classes | ||||||||||||||||||
|
Functions | ||
|