std::wcscspn(3)
π std::wcscspn(3) β the C++ Standard Library page, but make it make sense
Okay bestie, so this is the manual page for std::wcscspn from the C++ Standard Library, and I promise it's way less scary than the name looks π«Ά (wcscspn is literally just "wide char span" energy, iykyk).
β¨ NAME β¨
std::wcscspn β yes that's the whole name, she's self-titled, main character energy π
π Synopsis π
Defined in header <cwchar> π
std::size_t wcscspn( const wchar_t* dest, const wchar_t* src );
So here's the vibe: it returns the length of the maximum initial segment of the wide string pointed to by dest that consists of only the characters not found in the wide string pointed to by src.
Read that again, because the "not" is doing so much work π it counts how far you can walk through dest before you bump into anything from src. Periodt.
πΈ 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 π₯
Both of these are null-terminated wide strings, so nobody's out here guessing lengths, okay? They just keep reading until the null. Slay but also be careful π
π§ Return value π§
The length of the maximum initial segment that contains only characters not found in the character string pointed to by src β¨
That's it. That's the whole return. No cap.
π¦ Example π¦
The output below was obtained using clang (libc++). π
(the page literally has a // Run this code line right here, so here it is, verbatim, and then the code:)
// 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::wcscspn(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 3.
The segment is "η½η« ".
Not me getting emotional over a L'\0' being used to slam a terminator into place so the segment can be printed π iconic behaviour honestly.
π See also π
wcsspnβ returns the length of the maximum initial segment that consists of only the wide characters found in another wide string (function) π (yes she's the mirror-image sister, opposite energy, obsessed)wcspbrkβ finds the first location of any wide character in one wide string, in another wide string (function) π- C documentation for
wcscspnπ
Alright bestie, that's the whole page! This one came from http://cppreference.com, dated 2024.06.10, and it's the std::wcscspn(3) page π go forth and span those wide chars responsibly, ily πΈπ¦π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms