al_ustr_set_chr(3alleg5)
π al_ustr_set_chr β Allegro 5 API π
okay bestie, gather round, because this one is genuinely so useful and also lowkey a little bit dramatic if you play it wrong. it's al_ustr_set_chr, and it lives in the Allegro 5 API (that's the 3alleg5 manual section, iykyk). it swaps out one single code point for another. one. single. code point. no cap. π
β¨ SYNOPSIS β¨
#include <allegro5/allegro.h>
size_t al_ustr_set_chr(ALLEGRO_USTR *us, int start_pos, int32_t c)
look at her. so small. so powerful. π
πΈ DESCRIPTION πΈ
okay so here's the vibe: al_ustr_set_chr replaces the code point that begins at byte offset start_pos with c. that's it. that's the whole job. and she does it slayfully. β¨
but there are RULES, bestie, and we respect them:
start_poscannot be less than 0. like, don't even try it. that's not a thing. π- if
start_posis past the end ofus, then the space between the end of the string andstart_posgets padded withNUL('\0') bytes. yes, really, she'll just fill the gap with NULs like it's no big deal. iconic honestly. π - if
start_posis not the start of a valid code point, that is an error, and the string will be left unmodified. she simply refuses. no half-edits, no mess, the string stays exactly how it was. main character boundaries, periodt. π
and then the return value, which you need to actually read, ngl:
- on success β returns the number of bytes written, which is the offset to the following code point. so like, where the next character starts. π«Ά
- on error β returns
0. sad. tragic. zero. π
β οΈ real talk: the NUL-padding thing means this function can make your string longer than you might expect. that's not a bug, that's just the behavior. respect it.
π₯ SEE ALSO π₯
al_ustr_replace_range(3alleg5)β when you want to swap out a whole range instead of one lil code point, this is your girl π
π¦ a lil sign-off π¦
that's the whole page, bestie β brought to you by the Allegro reference manual, page al_ustr_set_chr(3alleg5). go forth, replace code points responsibly, and remember: if it returns 0, that's not a mood, that's an error. πβ¨π§
π¦ where this page comes from
- debian trixie: allegro5-doc 2:5.2.10.1+dfsg-1 Β· Zlib
- ubuntu questing: allegro5-doc 2:5.2.10.1+dfsg-1build1
- ubuntu resolute: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- ubuntu stonking: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms