Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.
/ fmtbuf Public archive

Buffered formatting that figures out the buffer size for you

License

Notifications You must be signed in to change notification settings

Hejsil/fmtbuf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fmtbuf

An alternative to std.fmt.bufPrintZ which can:

  • Automatically figure out the buffer size at compile time
  • Can be partially formatted, allowing for a prefix to be formatted and reused.
const FmtBuf = @import("fmtbuf").FmtBuf;
const std = @import("std");

test {
    var buf = FmtBuf("[{}] = {}", std.meta.Tuple(&.{ usize, u8 })){};
    try std.testing.expectEqualStrings("[0] = 0", buf.format(.{ 0, 0 }));
    try std.testing.expectEqualStrings("[12] = 3", buf.format(.{ 12, 3 }));

    var partial = buf.partialFormat(1, .{500});
    try std.testing.expectEqualStrings("[500] = 0", partial.format(.{0}));
    try std.testing.expectEqualStrings("[500] = 1", partial.format(.{1}));
    try std.testing.expectEqualStrings("[500] = 2", partial.format(.{2}));
}

About

Buffered formatting that figures out the buffer size for you

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages