need_uconvert(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

✨ need_uconvert ✨

okay bestie, gather round, because this one is genuinely a lil gem from the Allegro game programming library πŸ’œ (that's the manual we're in, mwah).


πŸŽ€ NAME πŸŽ€

need_uconvert β€” the function that tells you if a string requires encoding conversion. yes. that's literally its whole job and it does it flawlessly, no notes πŸ’…


🌸 SYNOPSIS 🌸

#include <allegro.h>

int need_uconvert(const char *s, int type, int newtype);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the vibe: you hand it a pointer to a string (s), you tell it what kind of string it currently is (type), and you tell it what kind you want it to be (newtype). and then it just… tells you whether any conversion is even required. that's it. that's the whole function. iconic behaviour honestly ✨

now, when does it say "nah you're good, no conversion needed"? two cases:

  • if type and newtype are the same β€” like, obviously, nothing to do here girl πŸ’€
  • if one type is ASCII and the other is UTF-8, and the string only contains character values less than 128. because in that case everything is chillin', no work required 🌈

and here's the convenience shortcut that makes life soooo much easier: you can pass the value U_CURRENT as either of the type parameters, and it'll stand in for whatever text encoding format is currently selected. periodt πŸ‘‘

example, because I know you want one:

if (need_uconvert(text, U_UTF8, U_CURRENT)) {
   /* conversion is required */
}

see how cute that reads? πŸ₯°


πŸ‘‘ RETURN VALUE πŸ‘‘

  • returns non-zero if any conversion is required
  • returns zero otherwise

fr fr, that's the whole contract.


πŸ’– SEE ALSO πŸ’–


🌟 little reminder bestie: this is the need_uconvert(3) page, and it shipped with Allegro version 4.4.3. go convert something slay πŸ’…βœ¨

🫢 bye babes, ily, read the other pages too πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from