aboutsummaryrefslogtreecommitdiff
path: root/lib/std/json/stringify.zig
diff options
context:
space:
mode:
authorJosh Wolfe <thejoshwolfe@gmail.com>2023-07-25 07:05:54 -0400
committerAndrew Kelley <andrew@ziglang.org>2023-07-27 10:23:58 -0700
commit8f2af35eaaf94493b4e459e14a1eda7ef00b7f64 (patch)
tree0b69d2f345d3ecaf7bfc6d9fc55459bafdb907f3 /lib/std/json/stringify.zig
parent49053cb1b4af7ee2973cf606def398c7eef6578b (diff)
downloadzig-8f2af35eaaf94493b4e459e14a1eda7ef00b7f64.tar.gz
zig-8f2af35eaaf94493b4e459e14a1eda7ef00b7f64.zip
std.json: WriteStream.print instead of writePreformatted
Diffstat (limited to 'lib/std/json/stringify.zig')
-rw-r--r--lib/std/json/stringify.zig12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/std/json/stringify.zig b/lib/std/json/stringify.zig
index 726dc571de..3e00531eaa 100644
--- a/lib/std/json/stringify.zig
+++ b/lib/std/json/stringify.zig
@@ -152,7 +152,7 @@ pub fn writeStreamArbitraryDepth(
/// | <object>
/// | <array>
/// | write
-/// | writePreformatted
+/// | print
/// <object> = beginObject ( objectField <value> )* endObject
/// <array> = beginArray ( <value> )* endArray
/// ```
@@ -378,13 +378,14 @@ pub fn WriteStream(
return self.indent_level == 0 and self.next_punctuation == .comma;
}
- /// An alternative to calling `write` that outputs the given bytes verbatim.
+ /// An alternative to calling `write` that formats a value with `std.fmt`.
/// This function does the usual punctuation and indentation formatting
- /// assuming the given slice represents a single complete value;
+ /// assuming the resulting formatted string represents a single complete value;
/// e.g. `"1"`, `"[]"`, `"[1,2]"`, not `"1,2"`.
- pub fn writePreformatted(self: *Self, value_slice: []const u8) Error!void {
+ /// This function may be useful for doing your own number formatting.
+ pub fn print(self: *Self, comptime fmt: []const u8, args: anytype) Error!void {
try self.valueStart();
- try self.stream.writeAll(value_slice);
+ try self.stream.print(fmt, args);
self.valueDone();
}
@@ -584,6 +585,7 @@ pub fn WriteStream(
pub const emitNumber = @compileError("Deprecated; Use .write() instead.");
pub const emitString = @compileError("Deprecated; Use .write() instead.");
pub const emitJson = @compileError("Deprecated; Use .write() instead.");
+ pub const writePreformatted = @compileError("Deprecated; Use .print(\"{s}\", .{s}) instead.");
};
}