| ... | @@ -725,7 +725,19 @@ pub fn stringify(writer: anytype, value: anytype, options: std.json.StringifyOpt | ... | @@ -725,7 +725,19 @@ pub fn stringify(writer: anytype, value: anytype, options: std.json.StringifyOpt |
| 725 | const T = @TypeOf(value); | 725 | const T = @TypeOf(value); |
| 726 | if (comptime extras.isZigString(T)) { | 726 | if (comptime extras.isZigString(T)) { |
| 727 | if (extras.matchesAll(u8, value, std.ascii.isAscii)) { | 727 | if (extras.matchesAll(u8, value, std.ascii.isAscii)) { |
| 728 | try writer.writevAll(&.{ &.{'"'}, value, &.{'"'} }); | 728 | if (extras.matchesAll(u8, value, std.ascii.isPrint)) { |
| | 729 | try writer.writevAll(&.{ &.{'"'}, value, &.{'"'} }); |
| | 730 | } else { |
| | 731 | try writer.writeAll("\""); |
| | 732 | for (value) |c| { |
| | 733 | try writer.writeAll(switch (c) { |
| | 734 | 0x20...0x7e => &.{c}, |
| | 735 | 0x0c => "\\n", |
| | 736 | else => "\\u00" ++ extras.to_hex([_]u8{c}), |
| | 737 | }); |
| | 738 | } |
| | 739 | try writer.writeAll("\""); |
| | 740 | } |
| 729 | } else { | 741 | } else { |
| 730 | @panic("TODO"); | 742 | @panic("TODO"); |
| 731 | } | 743 | } |
| ... | @@ -733,7 +745,19 @@ pub fn stringify(writer: anytype, value: anytype, options: std.json.StringifyOpt | ... | @@ -733,7 +745,19 @@ pub fn stringify(writer: anytype, value: anytype, options: std.json.StringifyOpt |
| 733 | } | 745 | } |
| 734 | if (comptime extras.isArrayOf(u8)(T)) { | 746 | if (comptime extras.isArrayOf(u8)(T)) { |
| 735 | if (extras.matchesAll(u8, &value, std.ascii.isAscii)) { | 747 | if (extras.matchesAll(u8, &value, std.ascii.isAscii)) { |
| 736 | try writer.writevAll(&.{ &.{'"'}, &value, &.{'"'} }); | 748 | if (extras.matchesAll(u8, value, std.ascii.isPrint)) { |
| | 749 | try writer.writevAll(&.{ &.{'"'}, &value, &.{'"'} }); |
| | 750 | } else { |
| | 751 | try writer.writeAll("\""); |
| | 752 | for (&value) |c| { |
| | 753 | try writer.writeAll(switch (c) { |
| | 754 | 0x20...0x7e => &.{c}, |
| | 755 | 0x0c => "\\n", |
| | 756 | else => "\\u00" ++ extras.to_hex([_]u8{c}), |
| | 757 | }); |
| | 758 | } |
| | 759 | try writer.writeAll("\""); |
| | 760 | } |
| 737 | } else { | 761 | } else { |
| 738 | @panic("TODO"); | 762 | @panic("TODO"); |
| 739 | } | 763 | } |