std::wcsspn(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌸 NAME 🌸

okay so this is std::wcsspn(3), from the C++ Standard Libary (yes, that’s the manual name, typo and all 😭), and she’s here to explain the wide-character β€œhow long is this matching prefix” situation. iconic πŸ’…

std::wcsspn - std::wcsspn ✨

✨ Synopsis ✨

Defined in header <cwchar>:

size_t wcsspn( const wchar_t* dest, const wchar_t* src );

Returns the length of the maximum initial segment of the wide string pointed to by dest, that consists of only the characters found in wide string pointed to by src. That’s the whole vibe, bestie β€” prefix matching but make it wide πŸ¦‹.

πŸ’– Parameters πŸ’–

  • dest β€” pointer to the null-terminated wide string to be analyzed 🌸
  • src β€” pointer to the null-terminated wide string that contains the characters to search for πŸ”

πŸŽ€ Return value πŸŽ€

The length of the maximum initial segment that contains only characters from the wide string pointed to by src. periodt πŸ’š

🧚 Example 🧚

Run this code, bestie:

// Run this code

#include <cwchar>
#include <iostream>
#include <locale>

int main()
{
    wchar_t dest[] = L"η™½ηŒ« ι»‘η‹— η”²θ™«";
    const wchar_t src[] = L" η‹—ηŒ« η™½ι»‘ ";
    const std::size_t len = std::wcsspn(dest, src);
    dest[len] = L'\0'; // terminates the segment to print it out

    std::wcout.imbue(std::locale("en_US.utf8"));
    std::wcout << L"The length of maximum initial segment is " << len
       << L".\n";
    std::wcout << L"The segment is \"" << dest << L"\".\n";
}

Possible output:

The length of maximum initial segment is 6.
The segment is "η™½ηŒ« ι»‘η‹— ".

πŸ¦‹ See also πŸ¦‹

  • wcscspn β€” function that returns the length of the maximum initial segment that consists of only the wide characters not found in another wide string πŸ‘€
  • wcspbrk β€” function that finds the first location of any wide character in one wide string, in another wide string πŸ”Ž
  • C documentation for wcsspn πŸ“š

Source/version/date tea β˜•: this page is from http://cppreference.com, with the 2024.06.10 version/date stamp. Bye bestie, go slay some wide strings! πŸ’…βœ¨πŸ«Ά

πŸ“¦ where this page comes from