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, maxlen specifies 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 character U+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 str1 is "less than" str2
  • returns greater than zero if str1 is "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