authorgravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2020-10-01 23:59:00+03:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-10-01 23:59:00+03:00
log5acf2a5068f762d69c406bc61309a9ab349aca72
treeb40c0ac5c668395e361ffe1042e7a7d3925c707a
parentbf0afaa876391571f6072650bf450356b26c928d
parent236af776fd21c76d7ca272f65355767413821011
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #6419 from tadeokondrak/std.fmt.comptimePrint

std.fmt: add comptimePrint

1 files changed, 10 insertions(+), 0 deletions(-)

lib/std/fmt.zig+10
......@@ -1181,6 +1181,16 @@ fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, opti
11811181 return buf[0..formatIntBuf(buf, value, base, uppercase, options)];
11821182}
11831183
1184pub fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt, args)]u8 {
1185 comptime var buf: [count(fmt, args)]u8 = undefined;
1186 _ = bufPrint(&buf, fmt, args) catch |err| @compileError(err);
1187 return &buf;
1188}
1189
1190test "comptimePrint" {
1191 std.testing.expectEqualSlices(u8, "100", comptime comptimePrint("{}", .{100}));
1192}
1193
11841194test "parse u64 digit too big" {
11851195 _ = parseUnsigned(u64, "123a", 10) catch |err| {
11861196 if (err == error.InvalidCharacter) return;