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 {...@@ -95,6 +95,8 @@ pub const Number = struct {
95/// - *fill* is a single byte which is used to pad formatted numbers.95/// - *fill* is a single byte which is used to pad formatted numbers.
96/// - *alignment* is one of the three bytes '<', '^', or '>' to make numbers96/// - *alignment* is one of the three bytes '<', '^', or '>' to make numbers
97/// left, center, or right-aligned, respectively.97/// 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.
98/// - *width* is the total width of the field in bytes. This only applies to number formatting.100/// - *width* is the total width of the field in bytes. This only applies to number formatting.
99/// - *precision* specifies how many decimals a formatted number should have.101/// - *precision* specifies how many decimals a formatted number should have.
100///102///
lib/std/io/Writer.zig+4-8
...@@ -851,19 +851,16 @@ pub fn printValue(...@@ -851,19 +851,16 @@ pub fn printValue(
851 .pointer => |info| switch (info.size) {851 .pointer => |info| switch (info.size) {
852 .one, .slice => {852 .one, .slice => {
853 const slice: []const u8 = value;853 const slice: []const u8 = value;
854 optionsForbidden(options); // Alignment not allowed on strings.854 return w.alignBufferOptions(slice, options);
855 return w.writeAll(slice);
856 },855 },
857 .many, .c => {856 .many, .c => {
858 const slice: [:0]const u8 = std.mem.span(value);857 const slice: [:0]const u8 = std.mem.span(value);
859 optionsForbidden(options); // Alignment not allowed on strings.858 return w.alignBufferOptions(slice, options);
860 return w.writeAll(slice);
861 },859 },
862 },860 },
863 .array => {861 .array => {
864 const slice: []const u8 = &value;862 const slice: []const u8 = &value;
865 optionsForbidden(options); // Alignment not allowed on strings.863 return w.alignBufferOptions(slice, options);
866 return w.writeAll(slice);
867 },864 },
868 else => invalidFmtError(fmt, value),865 else => invalidFmtError(fmt, value),
869 },866 },
...@@ -1118,8 +1115,7 @@ pub fn printValue(...@@ -1118,8 +1115,7 @@ pub fn printValue(
1118 .@"fn" => @compileError("unable to format function body type, use '*const " ++ @typeName(T) ++ "' for a function pointer type"),1115 .@"fn" => @compileError("unable to format function body type, use '*const " ++ @typeName(T) ++ "' for a function pointer type"),
1119 .type => {1116 .type => {
1120 if (!is_any and fmt.len != 0) invalidFmtError(fmt, value);1117 if (!is_any and fmt.len != 0) invalidFmtError(fmt, value);
1121 optionsForbidden(options);1118 return w.alignBufferOptions(@typeName(value), options);
1122 return w.writeAll(@typeName(value));
1123 },1119 },
1124 .enum_literal => {1120 .enum_literal => {
1125 if (!is_any and fmt.len != 0) invalidFmtError(fmt, value);1121 if (!is_any and fmt.len != 0) invalidFmtError(fmt, value);