我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用unicodedata.digit()。
def fast_int(x, key=lambda x: x, nan=None, uni=unicodedata.digit): """\ Convert a string to a int quickly, return input as-is if not possible. We don't need to accept all input that the real fast_int accepts because the input will be controlled by the splitting algorithm. """ if x[0] in '0123456789+-': try: return long(x) except ValueError: try: return uni(x, key(x)) if len(x) == 1 else key(x) except TypeError: # pragma: no cover return key(x) else: try: return uni(x, key(x)) if len(x) == 1 else key(x) except TypeError: # pragma: no cover return key(x)
def calibrate(self): data = (u'a', u'1', u' ', u'\u1234', u'\uFFFF') len_data = len(data) digit = unicodedata.digit numeric = unicodedata.numeric decimal = unicodedata.decimal category = unicodedata.category bidirectional = unicodedata.bidirectional decomposition = unicodedata.decomposition mirrored = unicodedata.mirrored combining = unicodedata.combining for i in xrange(self.rounds): c = data[i % len_data]
def fast_int(x, regex_matcher=int_re.match, uni=unicodedata.digit): """\ Convert a string to a int quickly, return input as-is if not possible. """ if type(x) in (int, long, float): return int(x) elif regex_matcher(x): return int(x.strip().rstrip('Ll')) elif type(x) == unicode and len(x) == 1 and uni(x, None) is not None: return uni(x) else: return x
def test(self): data = (u'a', u'1', u' ', u'\u1234', u'\uFFFF') len_data = len(data) digit = unicodedata.digit numeric = unicodedata.numeric decimal = unicodedata.decimal category = unicodedata.category bidirectional = unicodedata.bidirectional decomposition = unicodedata.decomposition mirrored = unicodedata.mirrored combining = unicodedata.combining for i in xrange(self.rounds): c = data[i % len_data] digit(c, None) numeric(c, None) decimal(c, None) category(c) bidirectional(c) decomposition(c) mirrored(c) combining(c) digit(c, None) numeric(c, None) decimal(c, None) category(c) bidirectional(c) decomposition(c) mirrored(c) combining(c) digit(c, None) numeric(c, None) decimal(c, None) category(c) bidirectional(c) decomposition(c) mirrored(c) combining(c) digit(c, None) numeric(c, None) decimal(c, None) category(c) bidirectional(c) decomposition(c) mirrored(c) combining(c) digit(c, None) numeric(c, None) decimal(c, None) category(c) bidirectional(c) decomposition(c) mirrored(c) combining(c)