authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-02 11:31:05-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2018-09-02 11:31:05-04:00
log86e55567b4b1cccbb69065396391e4a500864dce
treefb4bcfd5092e514a04ed7cae66d47d0a4787ae4b
parent78a110cda5bcd4593154d19feaff9cb4ac106fd4
parentd1752fbdc0d778fa92e97510f868ebbee5137329
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #1454 from kristate/str-hexbytes-issue1453

std.fmt: print zeroed high-order bytes correctly in hex

1 files changed, 3 insertions(+), 1 deletions(-)

std/fmt/index.zig+3-1
......@@ -352,7 +352,7 @@ pub fn formatText(
352352 return formatBuf(bytes, width, context, Errors, output);
353353 } else if ((fmt[0] == 'x') or (fmt[0] == 'X') ) {
354354 for (bytes) |c| {
355 try formatInt(c, 16, fmt[0] == 'X', 0, context, Errors, output);
355 try formatInt(c, 16, fmt[0] == 'X', 2, context, Errors, output);
356356 }
357357 return;
358358 } else @compileError("Unknown format character: " ++ []u8{fmt[0]});
......@@ -1281,6 +1281,8 @@ test "fmt.format" {
12811281 const some_bytes = "\xCA\xFE\xBA\xBE";
12821282 try testFmt("lowercase: cafebabe\n", "lowercase: {x}\n", some_bytes);
12831283 try testFmt("uppercase: CAFEBABE\n", "uppercase: {X}\n", some_bytes);
1284 const bytes_with_zeros = "\x00\x0E\xBA\xBE";
1285 try testFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", bytes_with_zeros);
12841286 }
12851287}
12861288