Skip to content

Commit

Permalink
std/fmt/index.zig: ziglang#1358 allow bytes to be printed-out as hex;
Browse files Browse the repository at this point in the history
Supports {x} for lowercase and {X} for uppercase;
  • Loading branch information
kristate committed Sep 1, 2018
1 parent e036f65 commit 454b236
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions std/fmt/index.zig
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,11 @@ pub fn formatText(
comptime var width = 0;
if (fmt.len > 1) width = comptime (parseUnsigned(usize, fmt[1..], 10) catch unreachable);
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);
}
return;
} else @compileError("Unknown format character: " ++ []u8{fmt[0]});
}
return output(context, bytes);
Expand Down

0 comments on commit 454b236

Please sign in to comment.