sdlStrlen function
This works exactly like strlen() but doesn't require access to a C runtime.
Counts the bytes in str
, excluding the null terminator.
If you need the length of a UTF-8 string, consider using SDL_utf8strlen().
\param str The null-terminated string to read. Must not be NULL.
\returns The length (in bytes, excluding the null terminator) of src
.
\threadsafety It is safe to call this function from any thread.
\since This function is available since SDL 3.1.3.
\sa SDL_strnlen \sa SDL_utf8strlen \sa SDL_utf8strnlen
extern SDL_DECLSPEC size_t SDLCALL SDL_strlen(const char *str)
Implementation
int sdlStrlen(String? str) {
final sdlStrlenLookupFunction = libSdl3.lookupFunction<
Uint32 Function(Pointer<Utf8> str),
int Function(Pointer<Utf8> str)>('SDL_strlen');
final strPointer = str != null ? str.toNativeUtf8() : nullptr;
final result = sdlStrlenLookupFunction(strPointer);
calloc.free(strPointer);
return result;
}