al_ustr_newf(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ al_ustr_newf ✨

okay so bestie, this one's from the Allegro 5 API manual (yes, 3alleg5, iykyk) and it's genuinely one of the most useful little functions in the whole string game πŸ’–


🌸 SYNOPSIS 🌸

#include <allegro5/allegro.h>

ALLEGRO_USTR *al_ustr_newf(const char *fmt, ...)

πŸ¦‹ DESCRIPTION πŸ¦‹

It makes you a brand new string, and it builds that string out of a printf-style format string. That's the whole vibe. You hand it a format, it hands you back a fresh ALLEGRO_USTR. iconic behavior honestly πŸ’…

Now. The notes. Because there are notes. And the notes are important, no cap 🚨

  • The %s specifier takes C string arguments, NOT ALLEGRO_USTRs. So if you wanna pass an ALLEGRO_USTR as a parameter you gotta go through al_cstr(3alleg5), and it must be NUL terminated. And like, be careful bestie: if the string contains an embedded NUL byte, everything from that byte onwards is just ignored. Gone. Poof. πŸ’€
  • The %c specifier outputs a single byte, not the UTF-8 encoding of a code point. So it's only usable for ASCII characters (value <= 127), OR if you literally and intentionally mean to output byte values from 128–255. That's it, that's the range.
So how do you actually put a code point's UTF-8 encoding in there? 🧚 You encode it into a memory buffer using al_utf8_encode(3alleg5), and then you use the %s specifier. And remember to NUL terminate that buffer. Do not forget. I'm watching. πŸ™ˆ

⭐ SEE ALSO ⭐


and that's the page, bestie!! go forth and format your little heart out πŸŽ€βœ¨

this has been the Allegro reference manual's page for al_ustr_newf(3alleg5) β€” same page, same name, forever and always πŸ«ΆπŸ’œ

πŸ“¦ where this page comes from