aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.zig
blob: a73a8ce1df1646486e2facf29dfaed8eb4f4e967 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const std = @import("std");

const state = struct {
    var buf: [256]u8 = undefined;
};
var fba = std.heap.FixedBufferAllocator.init(state.buf[0..]);

pub fn tmpZ(str: []const u8) ![:0]const u8 {
    fba.reset();
    return try std.fmt.allocPrintSentinel(fba.allocator(), "{s}", .{str}, 0);
}

pub fn tmpFmtZ(comptime fmt: []const u8, args: anytype) ![:0]const u8 {
    fba.reset();
    return try std.fmt.allocPrintSentinel(fba.allocator(), fmt, args, 0);
}

pub fn tmpJoinZ(separator: []const u8, slices: []const []const u8) ![:0]const u8 {
    fba.reset();
    return try std.mem.joinZ(fba.allocator(), separator, slices);
}