Fix formatter output length calculation.

This commit is contained in:
Christian Buttner
2025-01-10 21:05:30 +01:00
committed by Christoffer Lerno
parent e0afc0f9ea
commit 27970085e5
2 changed files with 9 additions and 8 deletions

View File

@@ -238,8 +238,7 @@ fn usz! Formatter.out_str(&self, any arg) @private
self.width = width;
}
self.width = 0;
self.out_substr("0x")!;
return self.ntoa_any(arg, 16);
return self.out_substr("0x")! + self.ntoa_any(arg, 16);
case ARRAY:
// this is SomeType[*] so grab the "SomeType"
PrintFlags flags = self.flags;
@@ -485,11 +484,14 @@ fn usz! Formatter.vprintf(&self, String format, any[] anys)
total_len += self.pad(' ', self.width, len)!;
continue;
}
OutputFn out_fn = self.out_fn;
self.out_fn = (OutputFn)&out_null_fn;
usz len = self.out_str(current)!;
self.out_fn = out_fn;
total_len += self.pad(' ', self.width, len)!;
if (self.width)
{
OutputFn out_fn = self.out_fn;
self.out_fn = (OutputFn)&out_null_fn;
usz len = self.out_str(current)!;
self.out_fn = out_fn;
total_len += self.pad(' ', self.width, len)!;
}
total_len += self.out_str(current)!;
continue;
case 'p':

View File

@@ -215,7 +215,6 @@ fn usz! Formatter.floatformat(&self, FloatFormatting formatting, double y) @priv
if (!self.flags.left) len += self.pad(' ', self.width, 3 + pl)!;
String s = self.flags.uppercase ? "INF" : "inf";
if (math::is_nan(y)) s = self.flags.uppercase ? "NAN" : "nan";
len += s.len;
if (pl) len += self.out(is_neg ? '-' : '+')!;
len += self.out_chars(s)!;
if (self.flags.left) len += self.pad(' ', self.width, 3 + pl)!;