std::iswctype(3)

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

πŸ’… std::iswctype πŸ’…

okay so we're in the C++ Standard Libary manual β€” yes, bestie, that's the manual name from the header, typo and all, and we're keeping it because it's iconic πŸ’…. This page is all about std::iswctype, and it's lowkey a little classification queen. πŸŽ€


🌸 NAME 🌸

std::iswctype β€” std::iswctype

yes, that's literally the whole NAME line, no notes, we move. πŸ¦‹


✨ Synopsis ✨

Defined in header <cwctype>
int iswctype( std::wint_t wc, std::wctype_t desc );

It classifies the wide character wc using the current C locale's LC_CTYPE category identified by desc. So it's like, "hey, what kind of character is this?" energy. πŸ”₯

🚨 If the value of wc is neither representable as a wchar_t nor equal to the value of the macro WEOF, the behavior is undefined. That's not a vibe, bestie β€” it's literally undefined behavior. πŸ’€

πŸŽ€ Parameters πŸŽ€

  • wc β€” the wide character to classify
  • desc β€” the LC_CTYPE category, obtained from a call to std::wctype

cute little duo, honestly. 🫢


πŸ‘‘ Return value πŸ‘‘

Non-zero if the character wc has the property identified by desc in the LC_CTYPE facet of the current C locale, zero otherwise. So it's giving yes-or-no, true-or-false, slay-or-nay. ⭐


🧚 Example 🧚

// Run this code

#include <clocale>
#include <cwctype>
#include <iostream>

bool classify(wchar_t wc, const std::string& cat)
{
    return std::iswctype(wc, std::wctype(cat.c_str()));
}

int main()
{
    std::setlocale(LC_ALL, "ja_JP.UTF-8");
    std::cout << "The character \u6c34 is...\n";
    for (std::string s : {"digit", "alpha", "space", "cntrl",
       "jkanji"})
        std::cout << s << "? " << std::boolalpha << classify(L'\u6c34',
       s) << '\n';
}

this example sets the locale to ja_JP.UTF-8 and then checks what the character 水 is, category by category. the way that jkanji just says true at the end? obsessed. 😭

πŸ’» Output πŸ’»

The character ζ°΄ is...
digit? false
alpha? true
space? false
cntrl? false
jkanji? true

look at that iconic little truth table. alpha? true, jkanji? true, and the rest are like "no bestie". 🌈


🌸 See also 🌸

  • wctype β€” looks up a character classification category in the current C locale (function)
  • C documentation for iswctype

go check those out if you want the full lore, iykyk. πŸ¦‹


okay bye bestie 🫢 β€” this page is from http://cppreference.com, dated 2024.06.10, and it's std::iswctype(3). mwah πŸ’‹

πŸ“¦ where this page comes from