From 48d3fbef5c3eb0c146979d3156c094fb23f45e8e Mon Sep 17 00:00:00 2001 From: kristopher tate Date: Sun, 2 Sep 2018 15:04:20 +0900 Subject: [PATCH 1/2] std/fmt/index.zig: set width from 0 to 2; \x00 was printed as 0 and \x0E was printed as E; \x00 now correctly prints 00 and \x0E correctly prints 0E; --- std/fmt/index.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/std/fmt/index.zig b/std/fmt/index.zig index 8e34bd43c4..345c46441d 100644 --- a/std/fmt/index.zig +++ b/std/fmt/index.zig @@ -352,7 +352,7 @@ pub fn formatText( return formatBuf(bytes, width, context, Errors, output); } else if ((fmt[0] == 'x') or (fmt[0] == 'X') ) { for (bytes) |c| { - try formatInt(c, 16, fmt[0] == 'X', 0, context, Errors, output); + try formatInt(c, 16, fmt[0] == 'X', 2, context, Errors, output); } return; } else @compileError("Unknown format character: " ++ []u8{fmt[0]}); From d1752fbdc0d778fa92e97510f868ebbee5137329 Mon Sep 17 00:00:00 2001 From: kristopher tate Date: Sun, 2 Sep 2018 15:04:57 +0900 Subject: [PATCH 2/2] std/fmt/index.zig: test for printing double width hex bytes with zeros; Co-Authored-By: Shawn Landden --- std/fmt/index.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/std/fmt/index.zig b/std/fmt/index.zig index 345c46441d..f9b68d7941 100644 --- a/std/fmt/index.zig +++ b/std/fmt/index.zig @@ -1281,6 +1281,8 @@ test "fmt.format" { const some_bytes = "\xCA\xFE\xBA\xBE"; try testFmt("lowercase: cafebabe\n", "lowercase: {x}\n", some_bytes); try testFmt("uppercase: CAFEBABE\n", "uppercase: {X}\n", some_bytes); + const bytes_with_zeros = "\x00\x0E\xBA\xBE"; + try testFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", bytes_with_zeros); } }