def _get_decomp_type(unichr): if unichr == u"\u2044": # FRACTION SLASH # special case this for CPython compatibility even though this returns as not being combining, eg, see # http://www.fileformat.info/info/unicode/char/2044/index.htm return "fraction" else: return _decomp[UCharacter.getIntPropertyValue(ord(unichr), UProperty.DECOMPOSITION_TYPE)]
def numeric(unichr, default=Nonesuch): n = UCharacter.getUnicodeNumericValue(_get_codepoint(unichr)) if n == UCharacter.NO_NUMERIC_VALUE: if default is not Nonesuch: return default else: raise ValueError("not a numeric") return n
def decimal(unichr, default=Nonesuch): d = UCharacter.getNumericValue(_get_codepoint(unichr)) if d < 0 or d > 9: if default is not Nonesuch: return default else: raise ValueError("not a decimal") return d
def digit(unichr, default=Nonesuch): d = UCharacter.digit(_get_codepoint(unichr)) if d == -1: if default is not Nonesuch: return default else: raise ValueError("not a digit") return d
def name(unichr, default=Nonesuch): # handle None n = UCharacter.getName(_get_codepoint(unichr)) if n is None: if default is not Nonesuch: return default else: raise ValueError("no such name") return n
def lookup(name): codepoint = UCharacter.getCharFromName(name) if codepoint == -1: raise KeyError("undefined character name '{}".format(name)) return unichr(codepoint)
def east_asian_width(unichr): return _eaw[UCharacter.getIntPropertyValue(_get_codepoint(unichr), UProperty.EAST_ASIAN_WIDTH)]
def mirrored(unichr): return UCharacter.isMirrored(_get_codepoint(unichr))
def combining(unichr): return UCharacter.getCombiningClass(_get_codepoint(unichr))
def bidirectional(unichr): return _dir[UCharacter.getDirection(_get_codepoint(unichr))]
def category(unichr): return _cat[UCharacter.getType(_get_codepoint(unichr))]