diff options
| author | Isaac Freund <ifreund@ifreund.xyz> | 2020-10-15 12:11:03 +0200 |
|---|---|---|
| committer | Isaac Freund <ifreund@ifreund.xyz> | 2020-10-15 12:21:19 +0200 |
| commit | d52035f4012f4f3225e2dcf9374b03ccd6600071 (patch) | |
| tree | 147a511e55f9ddfb300760f590b56233228f9d03 /lib | |
| parent | b259696cfba3c78b0641d30f159250465aa75af8 (diff) | |
| download | zig-d52035f4012f4f3225e2dcf9374b03ccd6600071.tar.gz zig-d52035f4012f4f3225e2dcf9374b03ccd6600071.zip | |
std/fmt: add bufPrintZ()
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/std/fmt.zig | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 2a5f17c159..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); |
