SDL_utf8strnlen(3)
π SDL_utf8strnlen π
okay bestie, so you know how we're in the SDL3 functions era and everything is cute and Unicode? yeah. this is SDL_utf8strnlen(3), and she counts the number of codepoints in a UTF-8 string, up to n bytes. slay.
β¨ SYNOPSIS β¨
#include <SDL3/SDL_stdinc.h>
size_t SDL_utf8strnlen(const char *str, size_t bytes);
πΈ DESCRIPTION πΈ
So like, this function counts the _codepoints_, not the _bytes_, in str β and it does not count the null terminator, okay? not about that life. π«Ά
If you actually need to count the bytes in a string instead, bestie, consider using SDL_strnlen(). she's right there. π
Now here's the plot twist: the counting stops at bytes bytes (not codepoints!!). it's giving counterintuitive, i know π, but it makes it easy to express the total size of the string's buffer. iconic design choice, fr fr.
And because this handles Unicode, it expects the strings to be well-formed UTF-8 β not a null-terminated string of arbitrary bytes. no chaos allowed. π Bytes that are not valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the count by several replacement characters. π yes, several. beware.
π FUNCTION PARAMETERS π
strβ the null-terminated UTF-8 string to read. Must not beNULL. like, seriously, do not.bytesβ the maximum amount of bytes to count.
β RETURN VALUE β
Returns the length (in codepoints, excluding the null terminator) of src but never more than maxlen.
π¦ THREAD SAFETY π¦
It is safe to call this function from any thread. go off, multithreaded queen. π
π AVAILABILITY π
This function is available since SDL 3.2.0.
π SEE ALSO π
okay that's the whole vibe check, bestie π Simple Directmedia Layer, SDL 3.4.18 β mwah, no notes, periodt. π β¨π
π¦ 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