(s, monetary=False)
| 135 | |
| 136 | #perform the grouping from right to left |
| 137 | def _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 |
| 168 | def _strip_padding(s, amount): |
no test coverage detected
searching dependent graphs…