BAN: If format string is started with space, numbers are padded with it

This commit is contained in:
Bananymous 2024-07-19 21:39:31 +03:00
parent 974b9b992d
commit 819c130366
1 changed files with 11 additions and 3 deletions

View File

@ -39,6 +39,7 @@ namespace BAN::Formatter
int base = 10; int base = 10;
int percision = 3; int percision = 3;
int fill = 0; int fill = 0;
char fill_char = '0';
bool upper = false; bool upper = false;
}; };
@ -94,6 +95,12 @@ namespace BAN::Formatter
if (!format[i] || format[i] == '}') if (!format[i] || format[i] == '}')
break; break;
if (format[i] == ' ')
{
value_format.fill_char = ' ';
i++;
}
if ('0' <= format[i] && format[i] <= '9') if ('0' <= format[i] && format[i] <= '9')
{ {
int fill = 0; int fill = 0;
@ -161,7 +168,8 @@ namespace BAN::Formatter
{ {
if (value == 0) if (value == 0)
{ {
for (int i = 0; i < format.fill || i < 1; i++) for (int i = 0; i < format.fill - 1; i++)
putc(format.fill_char);
putc('0'); putc('0');
return; return;
} }
@ -188,7 +196,7 @@ namespace BAN::Formatter
} }
while (ptr >= buffer + sizeof(buffer) - format.fill) while (ptr >= buffer + sizeof(buffer) - format.fill)
*(--ptr) = '0'; *(--ptr) = format.fill_char;
if (sign) if (sign)
*(--ptr) = '-'; *(--ptr) = '-';