SDL_strcasestr(3)

πŸ’– SDL_strcasestr β€” the "where's my substring tho" girlie πŸ’–

okay bestie, so this one lives in the SDL3 FUNCTIONS lineup, and her whole personality is: find the first place a substring shows up inside a bigger string, and do it case-insensitively. no cap. πŸŽ€


✨ NAME ✨

SDL_strcasestr β€” search a UTF-8 string for the first instance of a specific substring, case-insensitively.


✨ SYNOPSIS ✨

#include <SDL3/SDL_stdinc.h>

char * SDL_strcasestr(const char *haystack, const char *needle);

🌈 DESCRIPTION 🌈

so this bad girl works with Unicode strings, using a technique called "case-folding" β€” and she uses it to handle the vast majority of case-sensitive human languages regardless of system locale. she's not checking your locale settings, she simply does not care. πŸ‘‘

she can also deal with expanding values, which is the unhinged part: a German Eszett character can compare against two ASCII 's' chars and still be considered a match. like, one character eating two. iconic behavior honestly. πŸ’…

but there's a notable exception, and I need you to hear me on this: she does not handle the Turkish 'i' character. human language is complicated! 😭

and since she's doing Unicode, she expects the strings to be well-formed UTF-8 β€” not just a null-terminated string of arbitrary bytes. any bytes that aren't valid UTF-8 get treated as Unicode character U+FFFD (REPLACEMENT CHARACTER). which means, fr fr, two strings of random bits may turn out to match if they convert to the same amount of replacement characters. chaos! 🫠


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • haystack β€” the string to search. must not be NULL. 🚫
  • needle β€” the string to search for. must not be NULL. 🚫

⭐ RETURN VALUE ⭐

returns a pointer to the first instance of needle in the string, or NULL if it wasn't found. that's it, that's the tea. πŸ“


🧚 THREAD SAFETY 🧚

it is safe to call this function from any thread. go wild, multithreaded bestie, she can hang. πŸ”₯


πŸ’œ AVAILABILITY πŸ’œ

this function has been available since SDL 3.2.0. she's not new-new, but she's not ancient either. ✨


and that's the whole page, bestie!! πŸ¦‹ this one came straight from Simple Directmedia Layer, version SDL 3.4.18, and it's the SDL_strcasestr(3) page β€” go forth and case-fold responsibly πŸ’–πŸŒΈπŸ‘‘

πŸ“¦ where this page comes from