1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:57:35 +00:00

AK: Add option to the string formatter to use a digit separator

`vformat()` can now accept format specifiers of the form
{:'[numeric-type]}. This will output a number with a comma separator
every 3 digits.

For example:

`dbgln("{:'d}", 9999999);` will output 9,999,999.

Binary, octal and hexadecimal numbers can also use this feature, for
example:

`dbgln("{:'x}", 0xffffffff);` will output ff,fff,fff.
This commit is contained in:
Tim Ledbetter 2023-03-06 17:31:39 +00:00 committed by Jelle Raaijmakers
parent 605b4e96a8
commit 72ea046b68
5 changed files with 54 additions and 20 deletions

View file

@ -191,6 +191,7 @@ public:
bool prefix = false,
bool upper_case = false,
bool zero_pad = false,
bool use_separator = false,
Align align = Align::Right,
size_t min_width = 0,
char fill = ' ',
@ -203,6 +204,7 @@ public:
bool prefix = false,
bool upper_case = false,
bool zero_pad = false,
bool use_separator = false,
Align align = Align::Right,
size_t min_width = 0,
char fill = ' ',
@ -216,6 +218,7 @@ public:
u8 base = 10,
bool upper_case = false,
bool zero_pad = false,
bool use_separator = false,
Align align = Align::Right,
size_t min_width = 0,
size_t precision = 6,
@ -228,6 +231,7 @@ public:
long double value,
u8 base = 10,
bool upper_case = false,
bool use_separator = false,
Align align = Align::Right,
size_t min_width = 0,
size_t precision = 6,
@ -240,6 +244,7 @@ public:
u8 base = 10,
bool upper_case = false,
bool zero_pad = false,
bool use_separator = false,
Align align = Align::Right,
size_t min_width = 0,
size_t precision = 6,
@ -328,6 +333,7 @@ struct StandardFormatter {
FormatBuilder::SignMode m_sign_mode = FormatBuilder::SignMode::OnlyIfNeeded;
Mode m_mode = Mode::Default;
bool m_alternative_form = false;
bool m_use_separator = false;
char m_fill = ' ';
bool m_zero_pad = false;
Optional<size_t> m_width;