A string formatting library in 65 lines of C++

22 PaulHoule 9 9/15/2025, 3:51:28 PM riki.house ↗

Comments (9)

dpmdpm · 1h ago
I prefer https://github.com/rokudev/rostd/blob/main/doc/printx.adoc, but it does increase compile times (which OP was trying to avoid).
kevin_thibedeau · 2h ago

  char buffer[64];
  String_Buffer buf = {str, sizeof str};
Probably meant the "buffer" to be "str" here.
thw_9a83c · 1h ago
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 · 1h ago
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 · 1h ago
I much prefer string interpolation like

$"i={i}"

worstenbrood · 1h ago
Love the method name uhm bool next_hole
cppisnice · 2h ago
How many CVEs?
speed_spread · 39m ago
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.
shirol · 26m ago
Imagine creating a new account just to post this, smh