al_ustr_prev(3)
β¨ al_ustr_prev(3) β¨
okay bestie so this is a page from the Allegro 5 API reference manual (the Library Functions Manual, if we're being fancy π ) and it's about a tiny little function that walks backwards through a UTF-8 string. it's giving "reverse scavenger hunt" energy and honestly? kind of iconic.
πΈ SYNOPSIS πΈ
#include <allegro5/allegro.h>
bool al_ustr_prev(const ALLEGRO_USTR *us, int *pos)
literally just one include and one function call, we love a low-effort queen π
π¦ DESCRIPTION π¦
so here's the vibe: al_ustr_prev finds the byte offset of the previous code point in the string, the one sitting right before *pos. and the slayest part? *pos does not have to be at the beginning of a code point β it can be chilling anywhere, no pressure π
it returns true on success, and the value pointed to by pos gets updated to the found offset. cute, right?
but if *pos was already at the end of the string, it returns false and *pos stays totally unmodified. respectful king, doesn't touch what it doesn't need to π«Ά
β οΈ heads up bestie: this function just looks for an appropriate byte. it does not check whether the found offset is actually the beginning of a valid code point. so if you're working with possibly invalid UTF-8 strings, it could skip over some invalid bytes. no cap, watch out for that π
π SEE ALSO π
al_ustr_next(3)β the forward-walking sibling, go show it some love π
~ and that's the whole page, bestie ~ this gem comes to you from the Allegro reference manual and was dated according to the footer on the original page (source/version + date live right there in the footer, iykyk π). now go forth and iterate backwards with main character energy β¨π π
π¦ where this page comes from
- arch rolling: allegro 5.2.11.3-2 Β· Zlib AND BSD-3-Clause AND OFL-1.1 AND LicenseRef-Custom
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms