do_uconvert(3alleg4)

✨ do_uconvert ✨

okay bestie, welcome to the Allegro manual πŸ’– this one's from the Allegro game programming library and it's literally about converting strings between encodings. so niche, so useful, we love her 🫢


🌸 NAME 🌸

do_uconvert β€” converts a string to another encoding format πŸ’… (Allegro game programming library)


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <allegro.h>

void do_uconvert(const char *s, int type, char *buf, int newtype, int
size);

πŸ’œ DESCRIPTION πŸ’œ

okay so here's the vibe: this function takes the string s and converts it from type to newtype, and it drops the result into the output buffer buf β€” storing at most size bytes in there. no cap. πŸ“

and here's the cute part: the type parameters can use the value U_CURRENT as a lil shortcut that means "the currently selected encoding format" ✨ iykyk. like, instead of figuring out what you're currently working with, you just say U_CURRENT and she gets it.

example time, because we're visual learners:

char temp_string[256];
do_uconvert(input_string, U_CURRENT, temp_string, U_ASCII, 256);
🚨 GIRL. LISTEN. even for empty strings β€” even for EMPTY ones β€” your destination string still has to have at least enough bytes to store the terminating null character of the string, and your size parameter must reflect that. it's not optional, it's not a suggestion, it's the rules πŸ’€

and if you don't do it? oh honey 😭 two possibilities and both are bad:

  • the debug version of Allegro will abort at an assertion
  • the release version of Allegro will overrun the destination buffer

so like… give her the bytes she's asking for. protect your buffer. protect yourself. πŸ™ˆ


πŸŽ€ SEE ALSO πŸŽ€

  • uconvert(3alleg4) β€” the sibling, go say hi πŸ’•

alright that's the whole page, bestie, you're officially fluent in do_uconvert πŸ‘‘

this was brought to you by Allegro version 4.4.3 πŸŽ€ mwah, go convert something pretty ✨πŸ’