authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-09 15:17:07-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-09 15:17:07-07:00
log4d93545ded98b1e4da01e736ede6be726dc88c70
tree5c5b242876e6874ff6e3fde30e7ea006bd144c58
parent2468766a894d66037fb81791dc93fcb69e4c4055

chicken out and allow ascii string alignment


2 files changed, 6 insertions(+), 8 deletions(-)

lib/std/fmt.zig+2
......@@ -95,6 +95,8 @@ pub const Number = struct {
9595/// - *fill* is a single byte which is used to pad formatted numbers.
9696/// - *alignment* is one of the three bytes '<', '^', or '>' to make numbers
9797/// left, center, or right-aligned, respectively.
98/// - Not all specifiers support alignment.
99/// - Alignment is not Unicode-aware; appropriate only when used with raw bytes or ASCII.
98100/// - *width* is the total width of the field in bytes. This only applies to number formatting.
99101/// - *precision* specifies how many decimals a formatted number should have.
100102///
lib/std/io/Writer.zig+4-8
......@@ -851,19 +851,16 @@ pub fn printValue(
851851 .pointer => |info| switch (info.size) {
852852 .one, .slice => {
853853 const slice: []const u8 = value;
854 optionsForbidden(options); // Alignment not allowed on strings.
855 return w.writeAll(slice);
854 return w.alignBufferOptions(slice, options);
856855 },
857856 .many, .c => {
858857 const slice: [:0]const u8 = std.mem.span(value);
859 optionsForbidden(options); // Alignment not allowed on strings.
860 return w.writeAll(slice);
858 return w.alignBufferOptions(slice, options);
861859 },
862860 },
863861 .array => {
864862 const slice: []const u8 = &value;
865 optionsForbidden(options); // Alignment not allowed on strings.
866 return w.writeAll(slice);
863 return w.alignBufferOptions(slice, options);
867864 },
868865 else => invalidFmtError(fmt, value),
869866 },
......@@ -1118,8 +1115,7 @@ pub fn printValue(
11181115 .@"fn" => @compileError("unable to format function body type, use '*const " ++ @typeName(T) ++ "' for a function pointer type"),
11191116 .type => {
11201117 if (!is_any and fmt.len != 0) invalidFmtError(fmt, value);
1121 optionsForbidden(options);
1122 return w.writeAll(@typeName(value));
1118 return w.alignBufferOptions(@typeName(value), options);
11231119 },
11241120 .enum_literal => {
11251121 if (!is_any and fmt.len != 0) invalidFmtError(fmt, value);