authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-02-16 03:55:04-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-01 16:35:26-07:00
log221b194f284ecacccd208a2f760381f8d97805d7
treece4c7e0054c63fbb1cd281c1676c8906e1df466f
parent824216b1d4d3c643e14632ffe89e3d430be2e32a

std.io.BufferedWriter: implement hex string printing


1 files changed, 17 insertions(+), 5 deletions(-)

lib/std/io/BufferedWriter.zig+17-5
......@@ -769,12 +769,18 @@ pub fn printValue(
769769 },
770770 .slice => {
771771 if (actual_fmt.len == 0)
772 @compileError("cannot format slice without a specifier (i.e. {s} or {any})");
772 @compileError("cannot format slice without a specifier (i.e. {s}, {x}, or {any})");
773773 if (max_depth == 0) {
774774 return bw.writeAll("{ ... }");
775775 }
776 if (actual_fmt[0] == 's' and ptr_info.child == u8) {
777 return alignBufferOptions(bw, value, options);
776 if (ptr_info.child == u8) {
777 if (actual_fmt[0] == 's') {
778 return alignBufferOptions(bw, value, options);
779 } else if (actual_fmt[0] == 'x') {
780 return printHex(bw, value, .lower);
781 } else if (actual_fmt[0] == 'X') {
782 return printHex(bw, value, .upper);
783 }
778784 }
779785 try bw.writeAll("{ ");
780786 for (value, 0..) |elem, i| {
......@@ -792,8 +798,14 @@ pub fn printValue(
792798 if (max_depth == 0) {
793799 return bw.writeAll("{ ... }");
794800 }
795 if (actual_fmt[0] == 's' and info.child == u8) {
796 return alignBufferOptions(bw, &value, options);
801 if (info.child == u8) {
802 if (actual_fmt[0] == 's') {
803 return alignBufferOptions(bw, &value, options);
804 } else if (actual_fmt[0] == 'x') {
805 return printHex(bw, &value, .lower);
806 } else if (actual_fmt[0] == 'X') {
807 return printHex(bw, &value, .upper);
808 }
797809 }
798810 try bw.writeAll("{ ");
799811 for (value, 0..) |elem, i| {