sdlStrtokR function

Pointer<Int8> sdlStrtokR(
  1. Pointer<Int8> str,
  2. String? delim,
  3. Pointer<Pointer<Int8>> saveptr
)

This works exactly like strtok_r() but doesn't require access to a C runtime.

Break a string up into a series of tokens.

To start tokenizing a new string, str should be the non-NULL address of the string to start tokenizing. Future calls to get the next token from the same string should specify a NULL.

Note that this function will overwrite pieces of str with null chars to split it into tokens. This function cannot be used with const/read-only strings!

saveptr just needs to point to a char * that can be overwritten; SDL will use this to save tokenizing state between calls. It is initialized if str is non-NULL, and used to resume tokenizing when str is NULL.

\param str the string to tokenize, or NULL to continue tokenizing. \param delim the delimiter string that separates tokens. \param saveptr pointer to a char *, used for ongoing state. \returns A pointer to the next token, or NULL if no tokens remain.

\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_strtok_r(char *str, const char *delim, char **saveptr)

Implementation

Pointer<Int8> sdlStrtokR(
    Pointer<Int8> str, String? delim, Pointer<Pointer<Int8>> saveptr) {
  final sdlStrtokRLookupFunction = libSdl3.lookupFunction<
      Pointer<Int8> Function(Pointer<Int8> str, Pointer<Utf8> delim,
          Pointer<Pointer<Int8>> saveptr),
      Pointer<Int8> Function(Pointer<Int8> str, Pointer<Utf8> delim,
          Pointer<Pointer<Int8>> saveptr)>('SDL_strtok_r');
  final delimPointer = delim != null ? delim.toNativeUtf8() : nullptr;
  final result = sdlStrtokRLookupFunction(str, delimPointer, saveptr);
  calloc.free(delimPointer);
  return result;
}