SDL_wcsnstr(3)

✨ SDL_wcsnstr ✨

okay bestie, welcome to the SDL3 FUNCTIONS corner of the man pages πŸ’– this one is SDL_wcsnstr and she's lowkey a baddie: she searches a wide string, but only up to n wide chars, for the first instance of a specific substring. πŸŽ€


🌸 NAME 🌸

SDL_wcsnstr β€” search a wide string, up to n wide chars, for the first instance of a specific substring. slay. πŸ¦‹


πŸ’… SYNOPSIS πŸ’…

#include <SDL3/SDL_stdinc.h>

wchar_t * SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen);

✨ DESCRIPTION ✨

okay so the search stops the moment one of these three things happens, and you gotta know all three:

  • it finds the substring you asked for πŸ”₯
  • it hits a null terminator value that ends the string πŸ›‘
  • it has examined maxlen wide characters πŸ‘‘

and the cute part?? it is possible to use this function on a wide string without a null terminator. no terminator, no problem, we just count. πŸ’β€β™€οΈ

heads up bestie, this looks for strings of _wide characters_, not _codepoints_. so it's legal to search for malformed and incomplete UTF-16 sequences. it's giving raw and unbothered. 🫢

πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • haystack β€” the wide string to search. Must not be NULL. like literally do not. 😭
  • needle β€” the wide string to search for. Must not be NULL. same energy, don't do it. πŸ™ˆ
  • maxlen β€” the maximum number of wide characters to search in haystack. that's the whole point of the n, iykyk. ✨

πŸ‘‘ RETURN VALUE πŸ‘‘

Returns a pointer to the first instance of needle in the string, or NULL if not found. that's it, that's the vibe check. πŸ’€


🌈 THREAD SAFETY 🌈

It is safe to call this function from any thread. fr fr, any thread, she does not care. πŸ‘‘


⭐ AVAILABILITY ⭐

This function is available since SDL 3.2.0. so if you're on something older... bestie. upgrade. πŸ’…


and that's the whole page, periodt. this lil gem lives in Simple Directmedia Layer, SDL 3.4.18, and it's SDL_wcsnstr(3) in the manual, mwah πŸŽ€πŸ’–βœ¨πŸ¦‹πŸŒΈπŸ«Ά

πŸ“¦ where this page comes from