sdlStrnstr function
Search a string, up to n bytes, for the first instance of a specific substring.
The search ends once it finds the requested substring, or a null terminator
byte to end the string, or maxlen
bytes have been examined. It is
possible to use this function on a string without a null terminator.
Note that this looks for strings of bytes, not characters, so it's legal to search for malformed and incomplete UTF-8 sequences.
\param haystack the string to search. Must not be NULL.
\param needle the string to search for. Must not be NULL.
\param maxlen the maximum number of bytes to search in haystack
.
\returns a pointer to the first instance of needle
in the string, or NULL
if not found.
\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_strnstr(const char *haystack, const char *needle, size_t maxlen)
Implementation
Pointer<Int8> sdlStrnstr(String? haystack, String? needle, int maxlen) {
final sdlStrnstrLookupFunction = libSdl3.lookupFunction<
Pointer<Int8> Function(
Pointer<Utf8> haystack, Pointer<Utf8> needle, Uint32 maxlen),
Pointer<Int8> Function(Pointer<Utf8> haystack, Pointer<Utf8> needle,
int maxlen)>('SDL_strnstr');
final haystackPointer = haystack != null ? haystack.toNativeUtf8() : nullptr;
final needlePointer = needle != null ? needle.toNativeUtf8() : nullptr;
final result =
sdlStrnstrLookupFunction(haystackPointer, needlePointer, maxlen);
calloc.free(haystackPointer);
calloc.free(needlePointer);
return result;
}