authorgravatar for johnnymarler@gmail.comJonathan Marler <johnnymarler@gmail.com> 2021-01-03 13:49:51-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-07 23:49:22-08:00
log31802c6c68a98bdbe34766d3cfdaf65b782851da
tree88ea8704da9344e62347bee9b064d4c42cfdec83
parenta9b505fa7774e2e8451bedfa7bea27d7227572e7

remove z/Z format specifiers

Zig's format system is flexible enough to add custom formatters. This PR removes the new z/Z format specifiers that were added for printing Zig identifiers and replaces them with custom formatters.

10 files changed, 153 insertions(+), 110 deletions(-)

lib/std/build.zig+16-16
......@@ -1852,25 +1852,25 @@ pub const LibExeObjStep = struct {
18521852 const out = self.build_options_contents.writer();
18531853 switch (T) {
18541854 []const []const u8 => {
1855 out.print("pub const {z}: []const []const u8 = &[_][]const u8{{\n", .{name}) catch unreachable;
1855 out.print("pub const {}: []const []const u8 = &[_][]const u8{{\n", .{std.zig.fmtId(name)}) catch unreachable;
18561856 for (value) |slice| {
1857 out.print(" \"{Z}\",\n", .{slice}) catch unreachable;
1857 out.print(" \"{}\",\n", .{std.zig.fmtEscapes(slice)}) catch unreachable;
18581858 }
18591859 out.writeAll("};\n") catch unreachable;
18601860 return;
18611861 },
18621862 [:0]const u8 => {
1863 out.print("pub const {z}: [:0]const u8 = \"{Z}\";\n", .{ name, value }) catch unreachable;
1863 out.print("pub const {}: [:0]const u8 = \"{}\";\n", .{ std.zig.fmtId(name), std.zig.fmtEscapes(value) }) catch unreachable;
18641864 return;
18651865 },
18661866 []const u8 => {
1867 out.print("pub const {z}: []const u8 = \"{Z}\";\n", .{ name, value }) catch unreachable;
1867 out.print("pub const {}: []const u8 = \"{}\";\n", .{ std.zig.fmtId(name), std.zig.fmtEscapes(value) }) catch unreachable;
18681868 return;
18691869 },
18701870 ?[]const u8 => {
1871 out.print("pub const {z}: ?[]const u8 = ", .{name}) catch unreachable;
1871 out.print("pub const {}: ?[]const u8 = ", .{std.zig.fmtId(name)}) catch unreachable;
18721872 if (value) |payload| {
1873 out.print("\"{Z}\";\n", .{payload}) catch unreachable;
1873 out.print("\"{}\";\n", .{std.zig.fmtEscapes(payload)}) catch unreachable;
18741874 } else {
18751875 out.writeAll("null;\n") catch unreachable;
18761876 }
......@@ -1878,14 +1878,14 @@ pub const LibExeObjStep = struct {
18781878 },
18791879 std.builtin.Version => {
18801880 out.print(
1881 \\pub const {z}: @import("builtin").Version = .{{
1881 \\pub const {}: @import("builtin").Version = .{{
18821882 \\ .major = {d},
18831883 \\ .minor = {d},
18841884 \\ .patch = {d},
18851885 \\}};
18861886 \\
18871887 , .{
1888 name,
1888 std.zig.fmtId(name),
18891889
18901890 value.major,
18911891 value.minor,
......@@ -1894,23 +1894,23 @@ pub const LibExeObjStep = struct {
18941894 },
18951895 std.SemanticVersion => {
18961896 out.print(
1897 \\pub const {z}: @import("std").SemanticVersion = .{{
1897 \\pub const {}: @import("std").SemanticVersion = .{{
18981898 \\ .major = {d},
18991899 \\ .minor = {d},
19001900 \\ .patch = {d},
19011901 \\
19021902 , .{
1903 name,
1903 std.zig.fmtId(name),
19041904
19051905 value.major,
19061906 value.minor,
19071907 value.patch,
19081908 }) catch unreachable;
19091909 if (value.pre) |some| {
1910 out.print(" .pre = \"{Z}\",\n", .{some}) catch unreachable;
1910 out.print(" .pre = \"{}\",\n", .{std.zig.fmtEscapes(some)}) catch unreachable;
19111911 }
19121912 if (value.build) |some| {
1913 out.print(" .build = \"{Z}\",\n", .{some}) catch unreachable;
1913 out.print(" .build = \"{}\",\n", .{std.zig.fmtEscapes(some)}) catch unreachable;
19141914 }
19151915 out.writeAll("};\n") catch unreachable;
19161916 return;
......@@ -1919,15 +1919,15 @@ pub const LibExeObjStep = struct {
19191919 }
19201920 switch (@typeInfo(T)) {
19211921 .Enum => |enum_info| {
1922 out.print("pub const {z} = enum {{\n", .{@typeName(T)}) catch unreachable;
1922 out.print("pub const {} = enum {{\n", .{std.zig.fmtId(@typeName(T))}) catch unreachable;
19231923 inline for (enum_info.fields) |field| {
1924 out.print(" {z},\n", .{field.name}) catch unreachable;
1924 out.print(" {},\n", .{std.zig.fmtId(field.name)}) catch unreachable;
19251925 }
19261926 out.writeAll("};\n") catch unreachable;
19271927 },
19281928 else => {},
19291929 }
1930 out.print("pub const {z}: {s} = {};\n", .{ name, @typeName(T), value }) catch unreachable;
1930 out.print("pub const {}: {s} = {};\n", .{ std.zig.fmtId(name), @typeName(T), value }) catch unreachable;
19311931 }
19321932
19331933 /// The value is the path in the cache dir.
......@@ -2157,7 +2157,7 @@ pub const LibExeObjStep = struct {
21572157 // Render build artifact options at the last minute, now that the path is known.
21582158 for (self.build_options_artifact_args.items) |item| {
21592159 const out = self.build_options_contents.writer();
2160 out.print("pub const {s}: []const u8 = \"{Z}\";\n", .{ item.name, item.artifact.getOutputPath() }) catch unreachable;
2160 out.print("pub const {s}: []const u8 = \"{}\";\n", .{ item.name, std.zig.fmtEscapes(item.artifact.getOutputPath()) }) catch unreachable;
21612161 }
21622162
21632163 const build_options_file = try fs.path.join(
lib/std/fmt.zig+29-60
......@@ -715,9 +715,9 @@ pub fn formatText(
715715 }
716716 return;
717717 } else if (comptime std.mem.eql(u8, fmt, "z")) {
718 return formatZigIdentifier(bytes, options, writer);
718 @compileError("specifier 'z' has been deprecated, wrap your argument in std.zig.fmtId instead");
719719 } else if (comptime std.mem.eql(u8, fmt, "Z")) {
720 return formatZigEscapes(bytes, options, writer);
720 @compileError("specifier 'Z' has been deprecated, wrap your argument in std.zig.fmtEscapes instead");
721721 } else {
722722 @compileError("Unknown format string: '" ++ fmt ++ "'");
723723 }
......@@ -782,52 +782,6 @@ pub fn formatBuf(
782782 }
783783}
784784
785/// Print the string as a Zig identifier escaping it with @"" syntax if needed.
786pub fn formatZigIdentifier(
787 bytes: []const u8,
788 options: FormatOptions,
789 writer: anytype,
790) !void {
791 if (isValidZigIdentifier(bytes)) {
792 return writer.writeAll(bytes);
793 }
794 try writer.writeAll("@\"");
795 try formatZigEscapes(bytes, options, writer);
796 try writer.writeByte('"');
797}
798
799fn isValidZigIdentifier(bytes: []const u8) bool {
800 for (bytes) |c, i| {
801 switch (c) {
802 '_', 'a'...'z', 'A'...'Z' => {},
803 '0'...'9' => if (i == 0) return false,
804 else => return false,
805 }
806 }
807 return std.zig.Token.getKeyword(bytes) == null;
808}
809
810pub fn formatZigEscapes(
811 bytes: []const u8,
812 options: FormatOptions,
813 writer: anytype,
814) !void {
815 for (bytes) |byte| switch (byte) {
816 '\n' => try writer.writeAll("\\n"),
817 '\r' => try writer.writeAll("\\r"),
818 '\t' => try writer.writeAll("\\t"),
819 '\\' => try writer.writeAll("\\\\"),
820 '"' => try writer.writeAll("\\\""),
821 '\'' => try writer.writeAll("\\'"),
822 ' ', '!', '#'...'&', '('...'[', ']'...'~' => try writer.writeByte(byte),
823 // Use hex escapes for rest any unprintable characters.
824 else => {
825 try writer.writeAll("\\x");
826 try formatInt(byte, 16, false, .{ .width = 2, .fill = '0' }, writer);
827 },
828 };
829}
830
831785/// Print a float in scientific notation to the specified precision. Null uses full precision.
832786/// It should be the case that every full precision, printed value can be re-parsed back to the
833787/// same type unambiguously.
......@@ -1173,6 +1127,32 @@ pub const ParseIntError = error{
11731127 InvalidCharacter,
11741128};
11751129
1130/// Creates a Formatter type from a format function. Wrapping data in Formatter(func) causes
1131/// the data to be formatted using the given function `func`. `func` must be of the following
1132/// form:
1133///
1134/// fn formatExample(
1135/// data: T,
1136/// comptime fmt: []const u8,
1137/// options: std.fmt.FormatOptions,
1138/// writer: anytype,
1139/// ) !void;
1140///
1141pub fn Formatter(comptime format_fn: anytype) type {
1142 const Data = @typeInfo(@TypeOf(format_fn)).Fn.args[0].arg_type.?;
1143 return struct {
1144 data: Data,
1145 pub fn format(
1146 self: @This(),
1147 comptime fmt: []const u8,
1148 options: std.fmt.FormatOptions,
1149 writer: anytype,
1150 ) @TypeOf(writer).Error!void {
1151 try format_fn(self.data, fmt, options, writer);
1152 }
1153 };
1154}
1155
11761156/// Parses the string `buf` as signed or unsigned representation in the
11771157/// specified radix of an integral value of type `T`.
11781158///
......@@ -1608,17 +1588,6 @@ test "escape non-printable" {
16081588 try testFmt("ab\\xFFc", "{E}", .{"ab\xffc"});
16091589}
16101590
1611test "escape invalid identifiers" {
1612 try testFmt("@\"while\"", "{z}", .{"while"});
1613 try testFmt("hello", "{z}", .{"hello"});
1614 try testFmt("@\"11\\\"23\"", "{z}", .{"11\"23"});
1615 try testFmt("@\"11\\x0f23\"", "{z}", .{"11\x0F23"});
1616 try testFmt("\\x0f", "{Z}", .{0x0f});
1617 try testFmt(
1618 \\" \\ hi \x07 \x11 \" derp \'"
1619 , "\"{Z}\"", .{" \\ hi \x07 \x11 \" derp '"});
1620}
1621
16221591test "pointer" {
16231592 {
16241593 const value = @intToPtr(*align(1) i32, 0xdeadbeef);
......@@ -1898,7 +1867,7 @@ test "bytes.hex" {
18981867 try testFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", .{bytes_with_zeros});
18991868}
19001869
1901fn testFmt(expected: []const u8, comptime template: []const u8, args: anytype) !void {
1870pub fn testFmt(expected: []const u8, comptime template: []const u8, args: anytype) !void {
19021871 var buf: [100]u8 = undefined;
19031872 const result = try bufPrint(buf[0..], template, args);
19041873 if (mem.eql(u8, result, expected)) return;
lib/std/fs/wasi.zig+1-1
......@@ -38,7 +38,7 @@ pub const PreopenType = union(PreopenTypeTag) {
3838 pub fn format(self: Self, comptime fmt: []const u8, options: std.fmt.FormatOptions, out_stream: anytype) !void {
3939 try out_stream.print("PreopenType{{ ", .{});
4040 switch (self) {
41 PreopenType.Dir => |path| try out_stream.print(".Dir = '{z}'", .{path}),
41 PreopenType.Dir => |path| try out_stream.print(".Dir = '{}'", .{std.zig.fmtId(path)}),
4242 }
4343 return out_stream.print(" }}", .{});
4444 }
lib/std/zig.zig+2
......@@ -8,6 +8,8 @@ const tokenizer = @import("zig/tokenizer.zig");
88
99pub const Token = tokenizer.Token;
1010pub const Tokenizer = tokenizer.Tokenizer;
11pub const fmtId = @import("zig/fmt.zig").fmtId;
12pub const fmtEscapes = @import("zig/fmt.zig").fmtEscapes;
1113pub const parse = @import("zig/parse.zig").parse;
1214pub const parseStringLiteral = @import("zig/string_literal.zig").parse;
1315pub const render = @import("zig/render.zig").render;
lib/std/zig/fmt.zig created+71
......@@ -0,0 +1,71 @@
1const std = @import("std");
2const mem = std.mem;
3
4/// Print the string as a Zig identifier escaping it with @"" syntax if needed.
5pub fn formatId(
6 bytes: []const u8,
7 comptime fmt: []const u8,
8 options: std.fmt.FormatOptions,
9 writer: anytype,
10) !void {
11 if (isValidId(bytes)) {
12 return writer.writeAll(bytes);
13 }
14 try writer.writeAll("@\"");
15 try formatEscapes(bytes, fmt, options, writer);
16 try writer.writeByte('"');
17}
18
19/// Return a Formatter for a Zig identifier
20pub fn fmtId(bytes: []const u8) std.fmt.Formatter(formatId) {
21 return .{ .data = bytes };
22}
23
24pub fn isValidId(bytes: []const u8) bool {
25 for (bytes) |c, i| {
26 switch (c) {
27 '_', 'a'...'z', 'A'...'Z' => {},
28 '0'...'9' => if (i == 0) return false,
29 else => return false,
30 }
31 }
32 return std.zig.Token.getKeyword(bytes) == null;
33}
34
35pub fn formatEscapes(
36 bytes: []const u8,
37 comptime fmt: []const u8,
38 options: std.fmt.FormatOptions,
39 writer: anytype,
40) !void {
41 for (bytes) |byte| switch (byte) {
42 '\n' => try writer.writeAll("\\n"),
43 '\r' => try writer.writeAll("\\r"),
44 '\t' => try writer.writeAll("\\t"),
45 '\\' => try writer.writeAll("\\\\"),
46 '"' => try writer.writeAll("\\\""),
47 '\'' => try writer.writeAll("\\'"),
48 ' ', '!', '#'...'&', '('...'[', ']'...'~' => try writer.writeByte(byte),
49 // Use hex escapes for rest any unprintable characters.
50 else => {
51 try writer.writeAll("\\x");
52 try std.fmt.formatInt(byte, 16, false, .{ .width = 2, .fill = '0' }, writer);
53 },
54 };
55}
56
57/// Return a Formatter for Zig Escapes
58pub fn fmtEscapes(bytes: []const u8) std.fmt.Formatter(formatEscapes) {
59 return .{ .data = bytes };
60}
61
62test "escape invalid identifiers" {
63 try std.fmt.testFmt("@\"while\"", "{}", .{fmtId("while")});
64 try std.fmt.testFmt("hello", "{}", .{fmtId("hello")});
65 try std.fmt.testFmt("@\"11\\\"23\"", "{}", .{fmtId("11\"23")});
66 try std.fmt.testFmt("@\"11\\x0f23\"", "{}", .{fmtId("11\x0F23")});
67 try std.fmt.testFmt("\\x0f", "{}", .{fmtEscapes("\x0f")});
68 try std.fmt.testFmt(
69 \\" \\ hi \x07 \x11 \" derp \'"
70 , "\"{}\"", .{fmtEscapes(" \\ hi \x07 \x11 \" derp '")});
71}
src/Compilation.zig+22-22
......@@ -2703,27 +2703,27 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8
27032703 \\pub const arch = Target.current.cpu.arch;
27042704 \\/// Deprecated
27052705 \\pub const endian = Target.current.cpu.arch.endian();
2706 \\pub const output_mode = OutputMode.{z};
2707 \\pub const link_mode = LinkMode.{z};
2706 \\pub const output_mode = OutputMode.{};
2707 \\pub const link_mode = LinkMode.{};
27082708 \\pub const is_test = {};
27092709 \\pub const single_threaded = {};
2710 \\pub const abi = Abi.{z};
2710 \\pub const abi = Abi.{};
27112711 \\pub const cpu: Cpu = Cpu{{
2712 \\ .arch = .{z},
2713 \\ .model = &Target.{z}.cpu.{z},
2714 \\ .features = Target.{z}.featureSet(&[_]Target.{z}.Feature{{
2712 \\ .arch = .{},
2713 \\ .model = &Target.{}.cpu.{},
2714 \\ .features = Target.{}.featureSet(&[_]Target.{}.Feature{{
27152715 \\
27162716 , .{
2717 @tagName(comp.bin_file.options.output_mode),
2718 @tagName(comp.bin_file.options.link_mode),
2717 std.zig.fmtId(@tagName(comp.bin_file.options.output_mode)),
2718 std.zig.fmtId(@tagName(comp.bin_file.options.link_mode)),
27192719 comp.bin_file.options.is_test,
27202720 comp.bin_file.options.single_threaded,
2721 @tagName(target.abi),
2722 @tagName(target.cpu.arch),
2723 generic_arch_name,
2724 target.cpu.model.name,
2725 generic_arch_name,
2726 generic_arch_name,
2721 std.zig.fmtId(@tagName(target.abi)),
2722 std.zig.fmtId(@tagName(target.cpu.arch)),
2723 std.zig.fmtId(generic_arch_name),
2724 std.zig.fmtId(target.cpu.model.name),
2725 std.zig.fmtId(generic_arch_name),
2726 std.zig.fmtId(generic_arch_name),
27272727 });
27282728
27292729 for (target.cpu.arch.allFeaturesList()) |feature, index_usize| {
......@@ -2742,10 +2742,10 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8
27422742 \\ }}),
27432743 \\}};
27442744 \\pub const os = Os{{
2745 \\ .tag = .{z},
2745 \\ .tag = .{},
27462746 \\ .version_range = .{{
27472747 ,
2748 .{@tagName(target.os.tag)},
2748 .{std.zig.fmtId(@tagName(target.os.tag))},
27492749 );
27502750
27512751 switch (target.os.getVersionRange()) {
......@@ -2828,8 +2828,8 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8
28282828 (comp.bin_file.options.skip_linker_dependencies and comp.bin_file.options.parent_compilation_link_libc);
28292829
28302830 try buffer.writer().print(
2831 \\pub const object_format = ObjectFormat.{z};
2832 \\pub const mode = Mode.{z};
2831 \\pub const object_format = ObjectFormat.{};
2832 \\pub const mode = Mode.{};
28332833 \\pub const link_libc = {};
28342834 \\pub const link_libcpp = {};
28352835 \\pub const have_error_return_tracing = {};
......@@ -2837,11 +2837,11 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8
28372837 \\pub const position_independent_code = {};
28382838 \\pub const position_independent_executable = {};
28392839 \\pub const strip_debug_info = {};
2840 \\pub const code_model = CodeModel.{z};
2840 \\pub const code_model = CodeModel.{};
28412841 \\
28422842 , .{
2843 @tagName(comp.bin_file.options.object_format),
2844 @tagName(comp.bin_file.options.optimize_mode),
2843 std.zig.fmtId(@tagName(comp.bin_file.options.object_format)),
2844 std.zig.fmtId(@tagName(comp.bin_file.options.optimize_mode)),
28452845 link_libc,
28462846 comp.bin_file.options.link_libcpp,
28472847 comp.bin_file.options.error_return_tracing,
......@@ -2849,7 +2849,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8
28492849 comp.bin_file.options.pic,
28502850 comp.bin_file.options.pie,
28512851 comp.bin_file.options.strip,
2852 @tagName(comp.bin_file.options.machine_code_model),
2852 std.zig.fmtId(@tagName(comp.bin_file.options.machine_code_model)),
28532853 });
28542854
28552855 if (comp.bin_file.options.is_test) {
src/codegen/c.zig+2-2
......@@ -169,8 +169,8 @@ pub const DeclGen = struct {
169169 .undef, .empty_struct_value, .empty_array => try writer.writeAll("{}"),
170170 .bytes => {
171171 const bytes = val.castTag(.bytes).?.data;
172 // TODO: make our own C string escape instead of using {Z}
173 try writer.print("\"{Z}\"", .{bytes});
172 // TODO: make our own C string escape instead of using std.zig.fmtEscapes
173 try writer.print("\"{}\"", .{std.zig.fmtEscapes(bytes)});
174174 },
175175 else => {
176176 // Fall back to generic implementation.
src/translate_c.zig+4-3
......@@ -2031,7 +2031,7 @@ fn transStringLiteral(
20312031 const bytes_ptr = stmt.getString_bytes_begin_size(&len);
20322032 const str = bytes_ptr[0..len];
20332033
2034 const token = try appendTokenFmt(rp.c, .StringLiteral, "\"{Z}\"", .{str});
2034 const token = try appendTokenFmt(rp.c, .StringLiteral, "\"{}\"", .{std.zig.fmtEscapes(str)});
20352035 const node = try rp.c.arena.create(ast.Node.OneToken);
20362036 node.* = .{
20372037 .base = .{ .tag = .StringLiteral },
......@@ -2944,7 +2944,8 @@ fn transCharLiteral(
29442944 if (val > 255)
29452945 break :blk try transCreateNodeInt(rp.c, val);
29462946 }
2947 const token = try appendTokenFmt(rp.c, .CharLiteral, "'{Z}'", .{@intCast(u8, val)});
2947 const val_array = [_]u8 { @intCast(u8, val) };
2948 const token = try appendTokenFmt(rp.c, .CharLiteral, "'{}'", .{std.zig.fmtEscapes(&val_array)});
29482949 const node = try rp.c.arena.create(ast.Node.OneToken);
29492950 node.* = .{
29502951 .base = .{ .tag = .CharLiteral },
......@@ -5315,7 +5316,7 @@ fn isZigPrimitiveType(name: []const u8) bool {
53155316}
53165317
53175318fn appendIdentifier(c: *Context, name: []const u8) !ast.TokenIndex {
5318 return appendTokenFmt(c, .Identifier, "{z}", .{name});
5319 return appendTokenFmt(c, .Identifier, "{}", .{std.zig.fmtId(name)});
53195320}
53205321
53215322fn transCreateNodeIdentifier(c: *Context, name: []const u8) !*ast.Node {
src/value.zig+2-2
......@@ -491,8 +491,8 @@ pub const Value = extern union {
491491 val = elem_ptr.array_ptr;
492492 },
493493 .empty_array => return out_stream.writeAll(".{}"),
494 .enum_literal => return out_stream.print(".{z}", .{self.castTag(.enum_literal).?.data}),
495 .bytes => return out_stream.print("\"{Z}\"", .{self.castTag(.bytes).?.data}),
494 .enum_literal => return out_stream.print(".{}", .{std.zig.fmtId(self.castTag(.enum_literal).?.data)}),
495 .bytes => return out_stream.print("\"{}\"", .{std.zig.fmtEscapes(self.castTag(.bytes).?.data)}),
496496 .repeated => {
497497 try out_stream.writeAll("(repeated) ");
498498 val = val.castTag(.repeated).?.data;
src/zir.zig+4-4
......@@ -1308,17 +1308,17 @@ const Writer = struct {
13081308 try stream.writeByte('}');
13091309 },
13101310 bool => return stream.writeByte("01"[@boolToInt(param)]),
1311 []u8, []const u8 => return stream.print("\"{Z}\"", .{param}),
1311 []u8, []const u8 => return stream.print("\"{}\"", .{std.zig.fmtEscapes(param)}),
13121312 BigIntConst, usize => return stream.print("{}", .{param}),
13131313 TypedValue => return stream.print("TypedValue{{ .ty = {}, .val = {}}}", .{ param.ty, param.val }),
13141314 *IrModule.Decl => return stream.print("Decl({s})", .{param.name}),
13151315 *Inst.Block => {
13161316 const name = self.block_table.get(param).?;
1317 return stream.print("\"{Z}\"", .{name});
1317 return stream.print("\"{}\"", .{std.zig.fmtEscapes(name)});
13181318 },
13191319 *Inst.Loop => {
13201320 const name = self.loop_table.get(param).?;
1321 return stream.print("\"{Z}\"", .{name});
1321 return stream.print("\"{}\"", .{std.zig.fmtEscapes(name)});
13221322 },
13231323 [][]const u8 => {
13241324 try stream.writeByte('[');
......@@ -1326,7 +1326,7 @@ const Writer = struct {
13261326 if (i != 0) {
13271327 try stream.writeAll(", ");
13281328 }
1329 try stream.print("\"{Z}\"", .{str});
1329 try stream.print("\"{}\"", .{std.zig.fmtEscapes(str)});
13301330 }
13311331 try stream.writeByte(']');
13321332 },