Disable zero padding for signed integers

zero padding is mostly used with unsiged integers, and is quite difficult to
properly implement for signed integers. Disbaling iti n that case seems like a
good compromise
This commit is contained in:
Steins7 2024-04-15 23:10:31 +02:00
parent 0088322ee7
commit 254fec4f00

View File

@ -21,7 +21,7 @@ static uint32_t buffer_write(uint8_t byte, void* arg);
static uint32_t render_format(FormatCallback callback, void* arg,
const char* restrict format, va_list va);
static uint32_t render_signed(FormatCallback callback, void* arg,
int32_t number, uint8_t base, uint8_t width, bool zero_padding);
int32_t number, uint8_t base, uint8_t width);
static uint32_t render_unsigned(FormatCallback callback, void* arg,
uint32_t number, uint8_t base, uint8_t width, bool zero_padding);
@ -100,7 +100,7 @@ static uint32_t render_format(FormatCallback callback, void* arg,
break;
case 'i':
if (render_signed(callback, arg, va_arg(va, int32_t),
10, width, zero_padding)) {
10, width)) {
return 1;
}
break;
@ -158,7 +158,7 @@ static uint32_t render_format(FormatCallback callback, void* arg,
}
static uint32_t render_signed(FormatCallback callback, void* arg,
int32_t number, uint8_t base, uint8_t width, bool zero_padding)
int32_t number, uint8_t base, uint8_t width)
{
if (width > 0 && number < 0) {
--width;
@ -183,11 +183,7 @@ static uint32_t render_signed(FormatCallback callback, void* arg,
while (width > 0) {
--width;
if (zero_padding) {
if (callback('0', arg)) return 1;
} else {
if (callback(' ', arg)) return 1;
}
if (callback(' ', arg)) return 1;
}
}
@ -196,8 +192,7 @@ static uint32_t render_signed(FormatCallback callback, void* arg,
number = -number;
}
return render_unsigned(callback, arg, (uint32_t)number, base, 0,
zero_padding);
return render_unsigned(callback, arg, (uint32_t)number, base, 0, false);
}
static uint32_t render_unsigned(FormatCallback callback, void* arg,