Commit 4d93545ded

Andrew Kelley <andrew@ziglang.org>
2025-07-10 00:17:07
chicken out and allow ascii string alignment
1 parent 2468766
Changed files (2)
lib/std/io/Writer.zig
@@ -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);
lib/std/fmt.zig
@@ -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.
 ///