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 {...@@ -64,6 +64,7 @@ fn peekIsAlign(comptime fmt: []const u8) bool {
64/// - `e`: output floating point value in scientific notation64/// - `e`: output floating point value in scientific notation
65/// - `d`: output numeric value in decimal notation65/// - `d`: output numeric value in decimal notation
66/// - `b`: output integer value in binary notation66/// - `b`: output integer value in binary notation
67/// - `o`: output integer value in octal notation
67/// - `c`: output integer as an ASCII character. Integer type must have 8 bits at max.68/// - `c`: output integer as an ASCII character. Integer type must have 8 bits at max.
68/// - `*`: output the address of the value instead of the value itself.69/// - `*`: output the address of the value instead of the value itself.
69///70///
...@@ -543,6 +544,9 @@ pub fn formatIntValue(...@@ -543,6 +544,9 @@ pub fn formatIntValue(
543 } else if (comptime std.mem.eql(u8, fmt, "X")) {544 } else if (comptime std.mem.eql(u8, fmt, "X")) {
544 radix = 16;545 radix = 16;
545 uppercase = true;546 uppercase = true;
547 } else if (comptime std.mem.eql(u8, fmt, "o")) {
548 radix = 8;
549 uppercase = false;
546 } else {550 } else {
547 @compileError("Unknown format string: '" ++ fmt ++ "'");551 @compileError("Unknown format string: '" ++ fmt ++ "'");
548 }552 }
...@@ -1240,6 +1244,10 @@ test "int.specifier" {...@@ -1240,6 +1244,10 @@ test "int.specifier" {
1240 const value: u8 = 0b1100;1244 const value: u8 = 0b1100;
1241 try testFmt("u8: 0b1100\n", "u8: 0b{b}\n", .{value});1245 try testFmt("u8: 0b1100\n", "u8: 0b{b}\n", .{value});
1242 }1246 }
1247 {
1248 const value: u16 = 0o1234;
1249 try testFmt("u16: 0o1234\n", "u16: 0o{o}\n", .{value});
1250 }
1243}1251}
12441252
1245test "int.padded" {1253test "int.padded" {