authorgravatar for nue@envs.net~nue <nue@envs.net> 2020-07-14 02:27:58-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-07-14 02:27:58-04:00
log03f14c3102ccd3e1811ccf4fb7cae11a75d3018f
tree0f67c9d14bd5f906d0af62dedeba23c239ca4841
parentbc900cdeaf3434acc150a8db203eb5a485c09b67
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Added octal formatting fo `fmt` functions. (#5867)

* Added octal formatting (specifier "o") to `formatIntValue` function. * Added octal specifier test case in `fmt.zig` (under the "int.specifier" case)

1 files changed, 8 insertions(+), 0 deletions(-)

lib/std/fmt.zig+8
......@@ -64,6 +64,7 @@ fn peekIsAlign(comptime fmt: []const u8) bool {
6464/// - `e`: output floating point value in scientific notation
6565/// - `d`: output numeric value in decimal notation
6666/// - `b`: output integer value in binary notation
67/// - `o`: output integer value in octal notation
6768/// - `c`: output integer as an ASCII character. Integer type must have 8 bits at max.
6869/// - `*`: output the address of the value instead of the value itself.
6970///
......@@ -543,6 +544,9 @@ pub fn formatIntValue(
543544 } else if (comptime std.mem.eql(u8, fmt, "X")) {
544545 radix = 16;
545546 uppercase = true;
547 } else if (comptime std.mem.eql(u8, fmt, "o")) {
548 radix = 8;
549 uppercase = false;
546550 } else {
547551 @compileError("Unknown format string: '" ++ fmt ++ "'");
548552 }
......@@ -1240,6 +1244,10 @@ test "int.specifier" {
12401244 const value: u8 = 0b1100;
12411245 try testFmt("u8: 0b1100\n", "u8: 0b{b}\n", .{value});
12421246 }
1247 {
1248 const value: u16 = 0o1234;
1249 try testFmt("u16: 0o1234\n", "u16: 0o{o}\n", .{value});
1250 }
12431251}
12441252
12451253test "int.padded" {