diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 7e288170af..c9ba3b3470 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -64,6 +64,7 @@ fn peekIsAlign(comptime fmt: []const u8) bool { /// - `e`: output floating point value in scientific notation /// - `d`: output numeric value in decimal notation /// - `b`: output integer value in binary notation +/// - `o`: output integer value in octal notation /// - `c`: output integer as an ASCII character. Integer type must have 8 bits at max. /// - `*`: output the address of the value instead of the value itself. /// @@ -543,6 +544,9 @@ pub fn formatIntValue( } else if (comptime std.mem.eql(u8, fmt, "X")) { radix = 16; uppercase = true; + } else if (comptime std.mem.eql(u8, fmt, "o")) { + radix = 8; + uppercase = false; } else { @compileError("Unknown format string: '" ++ fmt ++ "'"); } @@ -1240,6 +1244,10 @@ test "int.specifier" { const value: u8 = 0b1100; try testFmt("u8: 0b1100\n", "u8: 0b{b}\n", .{value}); } + { + const value: u16 = 0o1234; + try testFmt("u16: 0o1234\n", "u16: 0o{o}\n", .{value}); + } } test "int.padded" {