SDL_UCS4ToUTF8(3)
β¨ SDL_UCS4ToUTF8(3) β¨
okay bestie so this one is a little function from the SDL3 FUNCTIONS crew and honestly? it's giving "tiny but mighty" π
πΈ NAME πΈ
SDL_UCS4ToUTF8 β convert a single Unicode codepoint to UTF-8. one codepoint in, up to four UTF-8 bytes out. that's the whole gig, and she does it flawlessly. periodt. β¨
π SYNOPSIS π
#include <SDL3/SDL_stdinc.h>
char * SDL_UCS4ToUTF8(Uint32 codepoint, char *dst);
π¦ DESCRIPTION π¦
so the buffer that dst points at? it must be at least 4 bytes long, no discussion, because this function may generate anywhere between 1 and 4 bytes of output. like, a tiny little codepoint might only need one byte, but some of them need the whole four. she's unpredictable in the cutest way π
this function returns the first byte after the newly-written UTF-8 sequence. and the way that is SO useful, okay? it means you can encode a bunch of codepoints in a loop and just keep feeding the return value back in, or you know exactly where to drop a NULL-terminator to end your string. in either of those cases, plan to have a buffer of more than 4 bytes!! like, 4 is the minimum for one call, not for a whole loop, bestie, don't do that to yourself π
if codepoint is an invalid value (outside the Unicode range, or a UTF-16 surrogate value, etc.), this will use U+FFFD (REPLACEMENT CHARACTER) for the codepoint instead, and it will not set an error. she's not mad, she's just gonna quietly hand you the little οΏ½ and move on π
if dst is NULL, this returns NULL immediately without writing to the pointer and without setting an error. no drama, no side effects, she just leaves. icon behavior honestly π
π FUNCTION PARAMETERS π
codepointβ a Unicode codepoint to convert to UTF-8. the little number you want turned into bytes πdstβ the location to write the encoded UTF-8. must point to at least 4 bytes! like actually actually. don't skip this part. π€
π RETURN VALUE π
returns the first byte past the newly-written UTF-8 sequence. that's your little bookmark for "next write goes here" π«Ά
β THREAD SAFETY β
it is safe to call this function from any thread. no cap, go wild, every thread gets a turn π
π AVAILABILITY π
this function is available since SDL 3.2.0. if you're on anything older she simply does not exist yet, sorry bestie πΈ
ok that's the whole page, mwah π go encode something cute and remember the 4-byte minimum, i'm begging you π
Simple Directmedia Layer β’ SDL 3.4.18 β’ SDL_UCS4ToUTF8(3) β that's the source, the version, and the page name all wrapped up in a lil sign-off, love u, bye! πβ¨π¦
π¦ 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