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:
Jeff Epler
2024-01-25 09:09:06 -06:00
committed by Damien George
parent f47e214cdc
commit 9032491efd
7 changed files with 32 additions and 21 deletions

View File

@@ -22,7 +22,17 @@ test("{:4o}", 123)
test("{:4x}", 123)
test("{:4X}", 123)
test("{:4,d}", 1)
test("{:4_d}", 1)
test("{:4_o}", 1)
test("{:4_b}", 1)
test("{:4_x}", 1)
test("{:4,d}", 12345678)
test("{:4_d}", 12345678)
test("{:4_o}", 12345678)
test("{:4_b}", 12345678)
test("{:4_x}", 12345678)
test("{:#4b}", 10)
test("{:#4o}", 123)