A string formatting library in 65 lines of C++
9 comments
·September 15, 2025kevin_thibedeau
char buffer[64];
String_Buffer buf = {str, sizeof str};
Probably meant the "buffer" to be "str" here.thw_9a83c
Clearly yes. BTW, I don't see a benefit to use a non-owning String_Buffer over std::string (or std::string_view) in this context.
kevin_thibedeau
The subtext is a resource constrained system where std::format is considered too heavyweight. In that scenario, explicit non-automatic memory management is a benefit. It could still leverage std::string_view and be agnostic on the topic.
vjvjvjvjghv
I much prefer string interpolation like
$"i={i}"
worstenbrood
Love the method name uhm bool next_hole
cppisnice
How many CVEs?
shirol
Imagine creating a new account just to post this, smh
speed_spread
Yes, true. But the probability of finding new CVEs from any 65 lines of non-obfuscated code diminishes rapidly. In many situations I'd rather use a short minimal fresh lib that I can review as if it was mine than a mature but overly feature-loaded one that may still have any number of pending gotchas in dark corners.
I prefer https://github.com/rokudev/rostd/blob/main/doc/printx.adoc, but it does increase compile times (which OP was trying to avoid).