From: Alex Morega Date: Sat, 6 Jul 2013 08:53:51 +0000 (+0200) Subject: move function to module level; fix doctest X-Git-Tag: 1.0~100^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c0e76d0d61a88807e992bed9387ca7b47268751;p=thirdparty%2Fbabel.git move function to module level; fix doctest --- diff --git a/babel/numbers.py b/babel/numbers.py index cecba347..9c0f8c66 100644 --- a/babel/numbers.py +++ b/babel/numbers.py @@ -420,6 +420,29 @@ def bankersround(value, ndigits=0): else: return float(int(value * scale + add)) / scale * sign + +def parse_grouping(p): + """Parse primary and secondary digit grouping + + >>> parse_grouping('##') + (1000, 1000) + >>> parse_grouping('#,###') + (3, 3) + >>> parse_grouping('#,####,###') + (3, 4) + """ + width = len(p) + g1 = p.rfind(',') + if g1 == -1: + return 1000, 1000 + g1 = width - g1 - 1 + g2 = p[:-g1 - 1].rfind(',') + if g2 == -1: + return g1, g1 + g2 = width - g1 - g2 - 2 + return g1, g2 + + def parse_pattern(pattern): """Parse number format patterns""" if isinstance(pattern, NumberPattern): @@ -469,27 +492,6 @@ def parse_pattern(pattern): break return min, max - def parse_grouping(p): - """Parse primary and secondary digit grouping - - >>> parse_grouping('##') - 0, 0 - >>> parse_grouping('#,###') - 3, 3 - >>> parse_grouping('#,####,###') - 3, 4 - """ - width = len(p) - g1 = p.rfind(',') - if g1 == -1: - return 1000, 1000 - g1 = width - g1 - 1 - g2 = p[:-g1 - 1].rfind(',') - if g2 == -1: - return g1, g1 - g2 = width - g1 - g2 - 2 - return g1, g2 - int_prec = parse_precision(integer) frac_prec = parse_precision(fraction) if exp: