SDL_iconv_utf8_ucs2(3)

πŸ’– SDL_iconv_utf8_ucs2 πŸ’–

okay bestie, welcome to the SDL_iconv_utf8_ucs2 page from the SDL3 crew (Simple Directmedia Layer, if we're being formal ✨) β€” it's a macro, it's cute, it turns your UTF-8 into UCS-2, and it lives in <SDL3/SDL_stdinc.h>. let's get into it πŸ¦‹


✨ NAME ✨

SDL_iconv_utf8_ucs2 β€” converts a UTF-8 string into UCS-2. that's it, that's the whole job, and it slays πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_stdinc.h>

#define SDL_iconv_utf8_ucs2(S)      SDL_reinterpret_cast(Uint16 *, SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1))

yes, that's the entire macro, no cap. it's a one-liner and it's iconic for it πŸ‘‘


πŸŽ€ DESCRIPTION πŸŽ€

so this is a helper macro, and the whole point of it is that it might be more clear than calling SDL_iconv_string directly. like, sometimes you just want the vibe to be readable, yk? 🫢

but bestie, listen, this is the important part: it double-evaluates its parameter. so do not use an expression with side-effects here. fr fr. if your argument does something spicy every time it's touched, it's gonna do that spicy thing twice, and that is not the moment πŸ’€

🧚 MACRO PARAMETERS 🧚

  • S β€” the string to convert. that's the one, the only, the main character of this macro 🌟

🌈 RETURN VALUE 🌈

it returns a new string, converted to the new encoding β€” or NULL on error. so like, check for NULL, bestie, don't just rawdog it into your code πŸ™ˆ


πŸ’œ THREAD SAFETY πŸ’œ

it is safe to call this macro from any thread. go wild, go parallel, go off πŸ”₯


⭐ AVAILABILITY ⭐

this macro has been available since SDL 3.2.0. so if you're on something older, sorry babe, no macro for you 😭


and that's the page!! mwah πŸ’– this was brought to you by Simple Directmedia Layer, SDL 3.4.18 β€” shoutout to the whole SDL3 era, couldn't have done it without you. go forth and convert your encodings, you absolute legend πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from