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(...@@ -769,12 +769,18 @@ pub fn printValue(
769 },769 },
770 .slice => {770 .slice => {
771 if (actual_fmt.len == 0)771 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})");
773 if (max_depth == 0) {773 if (max_depth == 0) {
774 return bw.writeAll("{ ... }");774 return bw.writeAll("{ ... }");
775 }775 }
776 if (actual_fmt[0] == 's' and ptr_info.child == u8) {776 if (ptr_info.child == u8) {
777 return alignBufferOptions(bw, value, options);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 }
778 }784 }
779 try bw.writeAll("{ ");785 try bw.writeAll("{ ");
780 for (value, 0..) |elem, i| {786 for (value, 0..) |elem, i| {
...@@ -792,8 +798,14 @@ pub fn printValue(...@@ -792,8 +798,14 @@ pub fn printValue(
792 if (max_depth == 0) {798 if (max_depth == 0) {
793 return bw.writeAll("{ ... }");799 return bw.writeAll("{ ... }");
794 }800 }
795 if (actual_fmt[0] == 's' and info.child == u8) {801 if (info.child == u8) {
796 return alignBufferOptions(bw, &value, options);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 }
797 }809 }
798 try bw.writeAll("{ ");810 try bw.writeAll("{ ");
799 for (value, 0..) |elem, i| {811 for (value, 0..) |elem, i| {