SDL_StepUTF8(3)
π SDL_StepUTF8 π
okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, where we decode UTF-8 one codepoint at a time and it's honestly kind of a serve β¨
πΈ NAME πΈ
SDL_StepUTF8 β decode a UTF-8 string, one Unicode codepoint at a time. she's a little stepper, she takes it slow, she's mindful π¦
β¨ SYNOPSIS β¨
#include <SDL3/SDL_stdinc.h>
Uint32 SDL_StepUTF8(const char **pstr, size_t *pslen);
π DESCRIPTION π
so here's the tea β: this function grabs the first Unicode codepoint out of the UTF-8 encoded string sitting in *pstr, and then β before it hands it back to you β it advances *pstr past all the bytes it just ate. like a lil cursor that scoots forward, no cap π«Ά
it will not access more than *pslen bytes from the string. and *pslen gets adjusted too, subtracting however many bytes got consumed. so both your pointer and your length stay in sync, they're a matching set, iconic π
pslen is allowed to be NULL, and in that case the string _must_ be NULL-terminated, because the function will just blindly read until it sees the NULL char. bestie. she's trusting. do not betray her π
if *pslen is zero, it assumes the end of string is reached and returns a zero codepoint, regardless of what's actually in the string buffer. don't even worry about it.
if the resulting codepoint is zero (that's a NULL terminator, btw) or *pslen is zero, it will not advance *pstr or *pslen at all. zero movement. standing perfectly still. main character pause π
generally you call this function in a loop until it returns zero, adjusting its parameters each iteration. that's the whole vibe β step, step, step, done π
now for the drama π if an invalid UTF-8 sequence shows up, this function returns SDL_INVALID_UNICODE_CODEPOINT and advances the string/length by one byte. which is to say: a multibyte sequence might produce several SDL_INVALID_UNICODE_CODEPOINT returns before it syncs back up to the next valid UTF-8 sequence. she's recalibrating. give her a sec β¨
several things can generate invalid UTF-8 sequences, including:
- overlong encodings
- the use of UTF-16 surrogate values
- truncated data
please refer to RFC3629 β¨https://www.ietf.org/rfc/rfc3629.txtβ© for details. iykyk π
π FUNCTION PARAMETERS π
pstrβ a pointer to a UTF-8 string pointer to be read and adjusted. yes that's a pointer to a pointer, she's layered, she has depth πpslenβ a pointer to the number of bytes in the string, to be read and adjusted.NULLis allowed π«Ά
π RETURN VALUE π
returns the first Unicode codepoint in the string. that's it, that's the gift π
π§ THREAD SAFETY π§
it is safe to call this function from any thread. go wild, take her everywhere, she's thread-safe π β¨
β AVAILABILITY β
this function is available since SDL 3.2.0. so if you're on something older... bestie. upgrade π
okay that's the whole page, mwah π this one came to you courtesy of Simple Directmedia Layer, version SDL 3.4.18, and the page itself is SDL_StepUTF8(3). go decode something beautiful, you absolute legend π¦ππ
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms