authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-10-15 20:51:25-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-10-15 20:51:25-04:00
logf701459f04e24a46faf3edc5121f81fbf132f436
tree0204062b98984abdc86162fb304564d4d0b074d9
parentcb44f27104937682ffaa42ec133e56595e4f08d0
parentd52035f4012f4f3225e2dcf9374b03ccd6600071
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #6685 from ifreund/bufprint0

std/fmt: rename allocPrint0() to allocPrintZ(), add bufPrintZ()

1 files changed, 9 insertions(+), 1 deletions(-)

lib/std/fmt.zig+9-1
...@@ -1131,6 +1131,11 @@ pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: anytype) BufPrintErro...@@ -1131,6 +1131,11 @@ pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: anytype) BufPrintErro
1131 return fbs.getWritten();1131 return fbs.getWritten();
1132}1132}
11331133
1134pub fn bufPrintZ(buf: []u8, comptime fmt: []const u8, args: anytype) BufPrintError![:0]u8 {
1135 const result = try bufPrint(buf, fmt ++ "\x00", args);
1136 return result[0 .. result.len - 1 :0];
1137}
1138
1134// Count the characters needed for format. Useful for preallocating memory1139// Count the characters needed for format. Useful for preallocating memory
1135pub fn count(comptime fmt: []const u8, args: anytype) u64 {1140pub fn count(comptime fmt: []const u8, args: anytype) u64 {
1136 var counting_writer = std.io.countingWriter(std.io.null_writer);1141 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...@@ -1151,7 +1156,10 @@ pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: any
1151 };1156 };
1152}1157}
11531158
1154pub fn allocPrint0(allocator: *mem.Allocator, comptime fmt: []const u8, args: anytype) AllocPrintError![:0]u8 {1159/// Deprecated, use allocPrintZ
1160pub const allocPrint0 = allocPrintZ;
1161
1162pub fn allocPrintZ(allocator: *mem.Allocator, comptime fmt: []const u8, args: anytype) AllocPrintError![:0]u8 {
1155 const result = try allocPrint(allocator, fmt ++ "\x00", args);1163 const result = try allocPrint(allocator, fmt ++ "\x00", args);
1156 return result[0 .. result.len - 1 :0];1164 return result[0 .. result.len - 1 :0];
1157}1165}