authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-02-25 01:37:08+11:00
committergravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-04-01 00:12:59+11:00
log17f5d04bedb7a3cf06e8b0a7a1e8d13a3f2635f5
tree73c24a6e59b674a3c70cf13323adf41b7ca6c2a7
parent5a053247e2c5cfb21af2dfdd3d7ffa56c33f7b67
signaturelock-open Commit is signed but in an unrecognized format.

std: use json.stringify logic in some json.WriteStream code paths


1 files changed, 3 insertions(+), 19 deletions(-)

lib/std/json/write_stream.zig+3-19
...@@ -140,11 +140,7 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {...@@ -140,11 +140,7 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
140140
141 pub fn emitBool(self: *Self, value: bool) !void {141 pub fn emitBool(self: *Self, value: bool) !void {
142 assert(self.state[self.state_index] == State.Value);142 assert(self.state[self.state_index] == State.Value);
143 if (value) {143 try std.json.stringify(value, std.json.StringifyOptions{}, self.stream);
144 try self.stream.writeAll("true");
145 } else {
146 try self.stream.writeAll("false");
147 }
148 self.popState();144 self.popState();
149 }145 }
150146
...@@ -185,20 +181,8 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {...@@ -185,20 +181,8 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
185 }181 }
186182
187 fn writeEscapedString(self: *Self, string: []const u8) !void {183 fn writeEscapedString(self: *Self, string: []const u8) !void {
188 try self.stream.writeByte('"');184 assert(std.unicode.utf8ValidateSlice(string));
189 for (string) |s| {185 try std.json.stringify(string, std.json.StringifyOptions{}, self.stream);
190 switch (s) {
191 '"' => try self.stream.writeAll("\\\""),
192 '\t' => try self.stream.writeAll("\\t"),
193 '\r' => try self.stream.writeAll("\\r"),
194 '\n' => try self.stream.writeAll("\\n"),
195 8 => try self.stream.writeAll("\\b"),
196 12 => try self.stream.writeAll("\\f"),
197 '\\' => try self.stream.writeAll("\\\\"),
198 else => try self.stream.writeByte(s),
199 }
200 }
201 try self.stream.writeByte('"');
202 }186 }
203187
204 /// Writes the complete json into the output stream188 /// Writes the complete json into the output stream