]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
move function to module level; fix doctest
authorAlex Morega <alex@grep.ro>
Sat, 6 Jul 2013 08:53:51 +0000 (10:53 +0200)
committerAlex Morega <alex@grep.ro>
Sat, 6 Jul 2013 12:54:57 +0000 (14:54 +0200)
babel/numbers.py

index cecba34780a7850f29b2a6c228bd4e34f3e7d8eb..9c0f8c66d9b24496fc297c8967dc690b81686ee0 100644 (file)
@@ -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: