diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index f40b763f9f..c9a203679e 100644 --- a/lib/std/fmt.zig +++ b/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. /// diff --git a/lib/std/io/Writer.zig b/lib/std/io/Writer.zig index 4b4fd76e02..4280d0b93e 100644 --- a/lib/std/io/Writer.zig +++ b/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);