Skip to content

Commit

Permalink
Merge pull request #1454 from kristate/str-hexbytes-issue1453
Browse files Browse the repository at this point in the history
std.fmt: print zeroed high-order bytes correctly in hex
  • Loading branch information
andrewrk committed Sep 2, 2018
2 parents 78a110c + d1752fb commit 86e5556
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion std/fmt/index.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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]});
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 86e5556

Please sign in to comment.