sdlIconvOpen function stdinc

Pointer<SdlIconvT> sdlIconvOpen(
  1. String? tocode,
  2. String? fromcode
)

This function allocates a context for the specified character set conversion.

\param tocode The target character encoding, must not be NULL. \param fromcode The source character encoding, must not be NULL. \returns a handle that must be freed with SDL_iconv_close, or SDL_ICONV_ERROR on failure.

\since This function is available since SDL 3.2.0.

\sa SDL_iconv \sa SDL_iconv_close \sa SDL_iconv_string

extern SDL_DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode, const char *fromcode)

Implementation

Pointer<SdlIconvT> sdlIconvOpen(String? tocode, String? fromcode) {
  final sdlIconvOpenLookupFunction = _libSdl
      .lookupFunction<
        Pointer<SdlIconvT> Function(
          Pointer<Utf8> tocode,
          Pointer<Utf8> fromcode,
        ),
        Pointer<SdlIconvT> Function(
          Pointer<Utf8> tocode,
          Pointer<Utf8> fromcode,
        )
      >('SDL_iconv_open');
  final tocodePointer = tocode != null ? tocode.toNativeUtf8() : nullptr;
  final fromcodePointer = fromcode != null ? fromcode.toNativeUtf8() : nullptr;
  final result = sdlIconvOpenLookupFunction(tocodePointer, fromcodePointer);
  calloc
    ..free(tocodePointer)
    ..free(fromcodePointer);
  return result;
}