chicken out and allow ascii string alignment

This commit is contained in:
Andrew Kelley 2025-07-09 15:17:07 -07:00
parent 2468766a89
commit 4d93545ded
2 changed files with 6 additions and 8 deletions

View File

@ -95,6 +95,8 @@ pub const Number = struct {
/// - *fill* is a single byte which is used to pad formatted numbers.
/// - *alignment* is one of the three bytes '<', '^', or '>' to make numbers
/// left, center, or right-aligned, respectively.
/// - Not all specifiers support alignment.
/// - Alignment is not Unicode-aware; appropriate only when used with raw bytes or ASCII.
/// - *width* is the total width of the field in bytes. This only applies to number formatting.
/// - *precision* specifies how many decimals a formatted number should have.
///

View File

@ -851,19 +851,16 @@ pub fn printValue(
.pointer => |info| switch (info.size) {
.one, .slice => {
const slice: []const u8 = value;
optionsForbidden(options); // Alignment not allowed on strings.
return w.writeAll(slice);
return w.alignBufferOptions(slice, options);
},
.many, .c => {
const slice: [:0]const u8 = std.mem.span(value);
optionsForbidden(options); // Alignment not allowed on strings.
return w.writeAll(slice);
return w.alignBufferOptions(slice, options);
},
},
.array => {
const slice: []const u8 = &value;
optionsForbidden(options); // Alignment not allowed on strings.
return w.writeAll(slice);
return w.alignBufferOptions(slice, options);
},
else => invalidFmtError(fmt, value),
},
@ -1118,8 +1115,7 @@ pub fn printValue(
.@"fn" => @compileError("unable to format function body type, use '*const " ++ @typeName(T) ++ "' for a function pointer type"),
.type => {
if (!is_any and fmt.len != 0) invalidFmtError(fmt, value);
optionsForbidden(options);
return w.writeAll(@typeName(value));
return w.alignBufferOptions(@typeName(value), options);
},
.enum_literal => {
if (!is_any and fmt.len != 0) invalidFmtError(fmt, value);