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 be NULL. 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