SDL_strncasecmp(3)
π SDL_strncasecmp β bestie's guide to case-insensitive string comparing π
okay so welcome to the SDL3 FUNCTIONS page for SDL_strncasecmp, bestie, and let me tell you, this one is lowkey iconic β¨
π NAME π
SDL_strncasecmp β compare two UTF-8 strings, case-insensitively, up to a number of bytes. that's the whole vibe. π¦
β¨ SYNOPSIS β¨
#include <SDL3/SDL_stdinc.h>
int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
like, that's it. that's the whole signature. she's simple, she's elegant, she ate π
πΈ DESCRIPTION πΈ
so here's the tea π: this function works with Unicode strings, and it does that using a technique called "case-folding". it's giving "we handle the vast majority of case-sensitive human languages regardless of system locale" and honestly? obsessed.
it can deal with expanding values too, which is so cool β a German Eszett character can compare against two ASCII 's' chars and be considered a match, for example. periodt. π
but bestie... a notable exception: it does not handle the Turkish 'i' character. human language is complicated! π that's not a bug, that's just the way it is.
since this handles Unicode, it expects the string to be well-formed UTF-8 and not a null-terminated string of arbitrary bytes. bytes that aren't valid UTF-8 get treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), which is to say two strings of random bits may turn out to match if they convert to the same amount of replacement characters. π so like... careful out there.
heads up, gorgeous: while this function is intended to be used with UTF-8,maxlenspecifies a _byte_ limit! if the limit lands in the middle of a multi-byte UTF-8 sequence, it may convert a portion of the final character to one or more Unicode characterU+FFFD(REPLACEMENT CHARACTER) so as not to overflow a buffer. she's polite like that π«Ά
maxlen specifies a maximum number of bytes to compare; if the strings match to this number of bytes (or both have matched to a null-terminator character before this number of bytes), they will be considered equal. slay. β
π«Ά FUNCTION PARAMETERS π«Ά
str1β the first string to compare. NULL is not permitted! don't even think about it πstr2β the second string to compare. NULL is not permitted! same energy, bestie. don't try it πmaxlenβ the maximum number of bytes to compare. that's the byte budget πΈ
π RETURN VALUE π
- returns less than zero if
str1is "less than"str2 - returns greater than zero if
str1is "greater than"str2 - returns zero if the strings match exactly
three outcomes, three vibes, all valid π
π§ THREAD SAFETY π§
it is safe to call this function from any thread. no cap. she's multithread-friendly, she's for the girls, she's for everybody π
β AVAILABILITY β
this function is available since SDL 3.2.0. so if you're on anything older... girl. upgrade. π₯
and that's the page, bestie!! π this was SDL_strncasecmp(3) from the Simple Directmedia Layer docs, SDL 3.4.18 edition β go forth, compare your strings, stay well-formed, and remember: NULL is never permitted, and the Turkish 'i' remains a mystery to us all. mwah πβ¨π
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms