Compare commits
No commits in common. "254fec4f006d6e1fee5e0d345122fd32c9230f51" and "e477055e6e3f5bf631fffdd8d0469116f1e73b77" have entirely different histories.
254fec4f00
...
e477055e6e
16
srv/format.c
16
srv/format.c
@ -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);
|
||||
int32_t number, uint8_t base, uint8_t width, bool zero_padding);
|
||||
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)) {
|
||||
10, width, zero_padding)) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
@ -121,7 +121,6 @@ static uint32_t render_format(FormatCallback callback, void* arg,
|
||||
zero_padding = true;
|
||||
continue;
|
||||
}
|
||||
// fall through
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
@ -158,7 +157,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)
|
||||
int32_t number, uint8_t base, uint8_t width, bool zero_padding)
|
||||
{
|
||||
if (width > 0 && number < 0) {
|
||||
--width;
|
||||
@ -183,7 +182,11 @@ static uint32_t render_signed(FormatCallback callback, void* arg,
|
||||
|
||||
while (width > 0) {
|
||||
--width;
|
||||
if (callback(' ', arg)) return 1;
|
||||
if (zero_padding) {
|
||||
if (callback('0', arg)) return 1;
|
||||
} else {
|
||||
if (callback(' ', arg)) return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,7 +195,8 @@ static uint32_t render_signed(FormatCallback callback, void* arg,
|
||||
number = -number;
|
||||
}
|
||||
|
||||
return render_unsigned(callback, arg, (uint32_t)number, base, 0, false);
|
||||
return render_unsigned(callback, arg, (uint32_t)number, base, 0,
|
||||
zero_padding);
|
||||
}
|
||||
|
||||
static uint32_t render_unsigned(FormatCallback callback, void* arg,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user