From 454b2362ee5e80dd1236535eaaec70d98e0d33ba Mon Sep 17 00:00:00 2001 From: kristopher tate Date: Sat, 1 Sep 2018 19:40:05 +0900 Subject: [PATCH] std/fmt/index.zig: #1358 allow bytes to be printed-out as hex; Supports {x} for lowercase and {X} for uppercase; --- std/fmt/index.zig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/std/fmt/index.zig b/std/fmt/index.zig index 6d23eebd0b71..a8ea5b4c5ada 100644 --- a/std/fmt/index.zig +++ b/std/fmt/index.zig @@ -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);