sdlIconvString function stdinc
Helper function to convert a string's encoding in one call.
This function converts a buffer or string between encodings in one pass.
The string does not need to be NULL-terminated; this function operates on
the number of bytes specified in inbytesleft
whether there is a NULL
character anywhere in the buffer.
The returned string is owned by the caller, and should be passed to SDL_free when no longer needed.
\param tocode the character encoding of the output string. Examples are
"UTF-8", "UCS-4", etc.
\param fromcode the character encoding of data in inbuf
.
\param inbuf the string to convert to a different encoding.
\param inbytesleft the size of the input string in bytes.
\returns a new string, converted to the new encoding, or NULL on error.
\since This function is available since SDL 3.2.0.
\sa SDL_iconv_open \sa SDL_iconv_close \sa SDL_iconv
extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft)
Implementation
Pointer<Int8> sdlIconvString(
String? tocode,
String? fromcode,
String? inbuf,
int inbytesleft,
) {
final sdlIconvStringLookupFunction = _libSdl
.lookupFunction<
Pointer<Int8> Function(
Pointer<Utf8> tocode,
Pointer<Utf8> fromcode,
Pointer<Utf8> inbuf,
Uint32 inbytesleft,
),
Pointer<Int8> Function(
Pointer<Utf8> tocode,
Pointer<Utf8> fromcode,
Pointer<Utf8> inbuf,
int inbytesleft,
)
>('SDL_iconv_string');
final tocodePointer = tocode != null ? tocode.toNativeUtf8() : nullptr;
final fromcodePointer = fromcode != null ? fromcode.toNativeUtf8() : nullptr;
final inbufPointer = inbuf != null ? inbuf.toNativeUtf8() : nullptr;
final result = sdlIconvStringLookupFunction(
tocodePointer,
fromcodePointer,
inbufPointer,
inbytesleft,
);
calloc
..free(tocodePointer)
..free(fromcodePointer)
..free(inbufPointer);
return result;
}