aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorkristopher tate <kris.tate+github@gmail.com>2018-09-01 19:40:05 +0900
committerkristopher tate <kris.tate+github@gmail.com>2018-09-01 19:40:05 +0900
commit454b2362ee5e80dd1236535eaaec70d98e0d33ba (patch)
treec8f8f4c177d022945de5f8783fb72808c93cc279 /std
parente036f65ac0df91b03dc6bcda8b043484321c6857 (diff)
downloadzig-454b2362ee5e80dd1236535eaaec70d98e0d33ba.tar.gz
zig-454b2362ee5e80dd1236535eaaec70d98e0d33ba.zip
std/fmt/index.zig: #1358 allow bytes to be printed-out as hex;
Supports {x} for lowercase and {X} for uppercase;
Diffstat (limited to 'std')
-rw-r--r--std/fmt/index.zig5
1 files changed, 5 insertions, 0 deletions
diff --git a/std/fmt/index.zig b/std/fmt/index.zig
index 6d23eebd0b..a8ea5b4c5a 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);