MCPcopy Index your code
hub / github.com/python/cpython / _group

Function _group

Lib/locale.py:137–165  ·  view source on GitHub ↗
(s, monetary=False)

Source from the content-addressed store, hash-verified

135
136#perform the grouping from right to left
137def _group(s, monetary=False):
138 conv = localeconv()
139 thousands_sep = conv[monetary and 'mon_thousands_sep' or 'thousands_sep']
140 grouping = conv[monetary and 'mon_grouping' or 'grouping']
141 if not grouping:
142 return (s, 0)
143 if s[-1] == ' ':
144 stripped = s.rstrip()
145 right_spaces = s[len(stripped):]
146 s = stripped
147 else:
148 right_spaces = ''
149 left_spaces = ''
150 groups = []
151 for interval in _grouping_intervals(grouping):
152 if not s or s[-1] not in "0123456789":
153 # only non-digit characters remain (sign, spaces)
154 left_spaces = s
155 s = ''
156 break
157 groups.append(s[-interval:])
158 s = s[:-interval]
159 if s:
160 groups.append(s)
161 groups.reverse()
162 return (
163 left_spaces + thousands_sep.join(groups) + right_spaces,
164 len(thousands_sep) * (len(groups) - 1)
165 )
166
167# Strip a given amount of excess padding from the given string
168def _strip_padding(s, amount):

Callers 1

_localizeFunction · 0.85

Calls 6

localeconvFunction · 0.85
_grouping_intervalsFunction · 0.85
rstripMethod · 0.45
appendMethod · 0.45
reverseMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…