SDL_utf8strlen(3)

✨ SDL_utf8strlen ✨

okay bestie, so this one's from the SDL3 functions corner of the SDL3 man pages, and it's literally just: how many characters are in this string, not how many bytes. codepoint counting, no cap. πŸ’…


🌸 NAME 🌸

SDL_utf8strlen β€” count the number of codepoints in a UTF-8 string.


πŸŽ€ SYNOPSIS πŸŽ€

#include <SDL3/SDL_stdinc.h>

size_t SDL_utf8strlen(const char *str);

πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the tea: it counts the _codepoints_, not the _bytes_, in str, and it does not count the null terminator. periodt.

If you actually want the byte count instead, girl, go use SDL_strlen(). different function, different vibe.

And because this one is doing real Unicode work, it expects your strings to be well-formed UTF-8 β€” not just a null-terminated pile of random bytes. Any bytes that aren't valid UTF-8 get treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), so heads up: a malformed or incomplete UTF-8 sequence might bump your count up by several replacement characters. like, surprise! 😭 it's giving "one broken char, five codepoints."


πŸ’– FUNCTION PARAMETERS πŸ’–

  • str β€” the null-terminated UTF-8 string to read. Must not be NULL. do not pass NULL, bestie, i'm begging. πŸ™ˆ

⭐ RETURN VALUE ⭐

Returns the length (in codepoints, excluding the null terminator) of src. yep, that's what it says β€” src. we love a lil naming moment. 🫢


🌈 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 πŸ“


and that's the whole page, no crumbs left πŸ’œ β€” brought to you by Simple Directmedia Layer, SDL 3.4.18, and this lil SDL_utf8strlen(3) moment. mwah, go count some codepoints. ✨

πŸ“¦ where this page comes from