| ... | @@ -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 { |
| 140 | | 140 | |
| 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 | } |
| 150 | | 146 | |
| ... | @@ -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 | } |
| 186 | | 182 | |
| 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 | } |
| 203 | | 187 | |
| 204 | /// Writes the complete json into the output stream | 188 | /// Writes the complete json into the output stream |