sdlUcs4ToUtf8 function

Pointer<Int8> sdlUcs4ToUtf8(
  1. int codepoint,
  2. Pointer<Int8> dst
)

Convert a single Unicode codepoint to UTF-8.

The buffer pointed to by dst must be at least 4 bytes long, as this function may generate between 1 and 4 bytes of output.

This function returns the first byte after the newly-written UTF-8 sequence, which is useful for encoding multiple codepoints in a loop, or knowing where to write a NULL-terminator character to end the string (in either case, plan to have a buffer of more than 4 bytes!).

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 not set an error.

If dst is NULL, this returns NULL immediately without writing to the pointer and without setting an error.

\param codepoint a Unicode codepoint to convert to UTF-8. \param dst the location to write the encoded UTF-8. Must point to at least 4 bytes! \returns the first byte past the newly-written UTF-8 sequence.

\threadsafety It is safe to call this function from any thread.

\since This function is available since SDL 3.1.3.

extern SDL_DECLSPEC char * SDLCALL SDL_UCS4ToUTF8(Uint32 codepoint, char *dst)

Implementation

Pointer<Int8> sdlUcs4ToUtf8(int codepoint, Pointer<Int8> dst) {
  final sdlUcs4ToUtf8LookupFunction = libSdl3.lookupFunction<
      Pointer<Int8> Function(Uint32 codepoint, Pointer<Int8> dst),
      Pointer<Int8> Function(
          int codepoint, Pointer<Int8> dst)>('SDL_UCS4ToUTF8');
  return sdlUcs4ToUtf8LookupFunction(codepoint, dst);
}