mirror of
https://github.com/micropython/micropython.git
synced 2026-01-06 20:20:14 +01:00
py/objstr: Add support for the :_b/o/x specifier in str.format.
This groups non-decimal values by fours, such as bbb_bbbb_bbbb. It also
supports `{:_d}` to use underscore for decimal numbers (grouped in threes).
Use of incorrect ":,b" is not diagnosed.
Thanks to @dpgeorge for the suggestion to reduce code size.
Signed-off-by: Jeff Epler <jepler@gmail.com>
This commit is contained in:
committed by
Damien George
parent
f47e214cdc
commit
9032491efd
@@ -1184,7 +1184,7 @@ static vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
|
||||
int width = -1;
|
||||
int precision = -1;
|
||||
char type = '\0';
|
||||
int flags = 0;
|
||||
unsigned int flags = 0;
|
||||
|
||||
if (format_spec) {
|
||||
// The format specifier (from http://docs.python.org/2/library/string.html#formatspec)
|
||||
@@ -1229,8 +1229,9 @@ static vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
|
||||
}
|
||||
}
|
||||
s = str_to_int(s, stop, &width);
|
||||
if (*s == ',') {
|
||||
flags |= PF_FLAG_SHOW_COMMA;
|
||||
if (*s == ',' || *s == '_') {
|
||||
MP_STATIC_ASSERT((unsigned)'_' << PF_FLAG_SEP_POS >> PF_FLAG_SEP_POS == '_');
|
||||
flags |= (unsigned)*s << PF_FLAG_SEP_POS;
|
||||
s++;
|
||||
}
|
||||
if (*s == '.') {
|
||||
|
||||
Reference in New Issue
Block a user