aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-10-15 20:51:25 -0400
committerGitHub <noreply@github.com>2020-10-15 20:51:25 -0400
commitf701459f04e24a46faf3edc5121f81fbf132f436 (patch)
tree0204062b98984abdc86162fb304564d4d0b074d9 /lib/std
parentcb44f27104937682ffaa42ec133e56595e4f08d0 (diff)
parentd52035f4012f4f3225e2dcf9374b03ccd6600071 (diff)
downloadzig-f701459f04e24a46faf3edc5121f81fbf132f436.tar.gz
zig-f701459f04e24a46faf3edc5121f81fbf132f436.zip
Merge pull request #6685 from ifreund/bufprint0
std/fmt: rename allocPrint0() to allocPrintZ(), add bufPrintZ()
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/fmt.zig10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig
index 92e5f9c392..a3a97020bf 100644
--- a/lib/std/fmt.zig
+++ b/lib/std/fmt.zig
@@ -1131,6 +1131,11 @@ pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: anytype) BufPrintErro
return fbs.getWritten();
}
+pub fn bufPrintZ(buf: []u8, comptime fmt: []const u8, args: anytype) BufPrintError![:0]u8 {
+ const result = try bufPrint(buf, fmt ++ "\x00", args);
+ return result[0 .. result.len - 1 :0];
+}
+
// Count the characters needed for format. Useful for preallocating memory
pub fn count(comptime fmt: []const u8, args: anytype) u64 {
var counting_writer = std.io.countingWriter(std.io.null_writer);
@@ -1151,7 +1156,10 @@ pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: any
};
}
-pub fn allocPrint0(allocator: *mem.Allocator, comptime fmt: []const u8, args: anytype) AllocPrintError![:0]u8 {
+/// Deprecated, use allocPrintZ
+pub const allocPrint0 = allocPrintZ;
+
+pub fn allocPrintZ(allocator: *mem.Allocator, comptime fmt: []const u8, args: anytype) AllocPrintError![:0]u8 {
const result = try allocPrint(allocator, fmt ++ "\x00", args);
return result[0 .. result.len - 1 :0];
}