std::wcscoll(3)
std::wcscoll(3) π β¨
okay bestie, this is the C++ Standard Libary manual page for std::wcscoll, and it is lowkey one of those functions that's giving "small but important." It's a wide-string compare that cares about locale collation rules. No cap. π
πΈ NAME πΈ
std::wcscoll β std::wcscoll. That's the name, bestie. Yes, the NAME section is giving copy-paste energy, but it's valid. π
π¦ Synopsis π¦
Defined in header <cwchar> β write that down. π«Ά
int wcscoll( const wchar_t* lhs, const wchar_t* rhs );
It compares two null-terminated wide strings according to the locale most recently installed by std::setlocale, as defined by the LC_COLLATE category. Literally that's the whole job. β¨
π Parameters π
lhs,rhsβ pointers to the null-terminated wide strings to compare. That's it, bestie. π
π Return value π
- Negative value if
lhsis less than (precedes)rhs. 0iflhsis equal torhs.- Positive value if
lhsis greater than (follows)rhs.
That's the whole vibe check. π«
β¨ Notes β¨
okay so collation order is dictionary order, bestie: the position of the letter in the national alphabet (its equivalence class) has higher priority than its case or variant. Within an equivalence class, lowercase characters collate before their uppercase equivalents, and locale-specific order may apply to the characters with diacritics. In some locales, groups of characters compare as single collation units. For example, "ch" in Czech follows "h" and precedes "i", and "dzs" in Hungarian follows "dz" and precedes "g". It's giving language lore. ππ
π₯ Example π₯
run this code, bestie:
// Run this code
#include <clocale>
#include <iostream>
void try_compare(const wchar_t* p1, const wchar_t* p2)
{
if (std::wcscoll(p1, p2) < 0)
std::wcout << p1 << " before " << p2 << '\n';
else
std::wcout << p2 << " before " << p1 << '\n';
}
int main()
{
std::setlocale(LC_ALL, "en_US.utf8");
std::wcout << "In the American locale: ";
try_compare(L"hrnec", L"chrt");
std::setlocale(LC_COLLATE, "cs_CZ.utf8");
std::wcout << "In the Czech locale: ";
try_compare(L"hrnec", L"chrt");
std::setlocale(LC_COLLATE, "en_US.utf8");
std::wcout << "In the American locale: ";
try_compare(L"Γ₯r", L"Γ€ngel");
std::setlocale(LC_COLLATE, "sv_SE.utf8");
std::wcout << "In the Swedish locale: ";
try_compare(L"Γ₯r", L"Γ€ngel");
}
π Output π
and the output is literally:
In the American locale: chrt before hrnec
In the Czech locale: hrnec before chrt
In the American locale: Γ€ngel before Γ₯r
In the Swedish locale: Γ₯r before Γ€ngel
π See also π
strcollβ compares two strings in accordance to the current locale (function).do_compareβ compares two strings using this facet's collation rules; it's tagged[virtual]and is a virtual protected member function ofstd::collate<CharT>.wcsxfrmβ transform a wide string so thatwcscmpwould produce the same result aswcscoll(function).- C documentation for
wcscoll.
β xoxo, from cppreference.com, version 2024.06.10, and yes this page is std::wcscoll(3) ππ«Ά
π¦ 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