SDL_strncmp(3)
β¨ SDL_strncmp β¨
okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual π β this one is SDL_strncmp, and she is literally the "compare two UTF-8 strings, but like, only up to a certain number of bytes" girlie. no cap. π
πΈ NAME πΈ
SDL_strncmp β compare two UTF-8 strings up to a number of bytes. π¦
β¨ SYNOPSIS β¨
#include <SDL3/SDL_stdinc.h>
int SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
π DESCRIPTION π
so here's the tea π: because UTF-8 is built the way it is, this function just works on Unicode strings β like, it's literally comparing bytes until it bumps into a null-terminating character. that's the whole vibe. and because UTF-8 is that girl, you can pair this with SDL_qsort() to sort your strings into (roughly) alphabetical order. iconic behavior, honestly. π
BUT β and this is the important part, bestie, don't skip it π β even though this function is meant for UTF-8, what it's actually doing is a bytewise comparison, and maxlen is a _byte_ limit, not a character limit! so if that limit lands right in the middle of a multi-byte UTF-8 sequence, it will only compare a portion of the final character. like it just stops mid-emoji. π lowkey cursed but that's the deal.
so what does maxlen actually mean? it's the maximum number of bytes to compare. if the strings match all the way up to that many bytes β or if both of them hit a null-terminator before that many bytes β then they get considered equal. periodt. β
π§ FUNCTION PARAMETERS π§
str1β the first string to compare.NULLis not permitted! π«str2β the second string to compare.NULLis not permitted! π«maxlenβ the maximum number of _bytes_ to compare. (bytes, not characters, iykyk π)
π RETURN VALUE π
- less than zero if
str1is "less than"str2π - greater than zero if
str1is "greater than"str2π₯ - zero if the strings match exactly β¨ (slay)
π THREAD SAFETY π
it is safe to call this function from any thread. π«Ά no drama, no notes.
β 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 was SDL_strncmp(3), served to you straight from Simple Directmedia Layer, version SDL 3.4.18, dated SDL_strncmp(3). go forth and compare bytes responsibly π
β¨π¦
π¦ 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