zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit d52035f4012f4f3225e2dcf9374b03ccd6600071 (tree)
parent b259696cfba3c78b0641d30f159250465aa75af8
Author: Isaac Freund <ifreund@ifreund.xyz>
Date:   Thu, 15 Oct 2020 12:11:03 +0200

std/fmt: add bufPrintZ()

Diffstat:
Mlib/std/fmt.zig | 5+++++
1 file changed, 5 insertions(+), 0 deletions(-)

diff --git 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);