std::iswalpha(3)

๐Ÿ“ฆ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

๐ŸŒธ std::iswalpha(3), but make it bestie-coded ๐ŸŒธ

So this is the std::iswalpha(3) page from the C++ Standard Libary manual โ€” yes, that spelling is in the header, and I'm folding the manual name in right here near the top like a little name tag, typo and all. No cap, it's a wide-character alphabet check. ๐Ÿ’…


โœจ NAME โœจ

std::iswalpha - std::iswalpha. That's the name, bestie. She's literally named std::iswalpha and she's doing exactly what it says on the tin. ๐ŸŽ€


๐Ÿ“œ Synopsis ๐Ÿ“œ

Defined in header <cwctype>:

int iswalpha( std::wint_t ch );

Okay so what it does: checks if the given wide character is an alphabetic character, i.e. either an uppercase letter (ABCDEFGHIJKLMNOPQRSTUVWXYZ), a lowercase letter (abcdefghijklmnopqrstuvwxyz) or any alphabetic character specific to the current locale. ๐ŸŒโœจ

๐Ÿšจ Danger zone, bestie: if the value of ch is neither representable as a wchar_t nor equal to the value of the macro WEOF, the behavior is undefined. Like, undefined undefined. Do not play with that. ๐Ÿ’€

๐ŸŽ€ Parameters ๐ŸŽ€

  • ch โ€” wide character. That's it. She's a wide character, your honor. ๐Ÿซถ

๐Ÿ”ฅ Return value ๐Ÿ”ฅ

Non-zero value if the wide character is an alphabetic character, 0 otherwise. So truthy = alpha, 0 = not alpha. Simple, iconic, periodt. ๐Ÿ‘‘


๐Ÿฆ‹ Notes ๐Ÿฆ‹

ISO 30112 specifies which Unicode characters are include in POSIX alpha category. (Yes, "include" is the original wording โ€” I'm not fixing it, I'm just delivering the facts with a cute bow on top. ๐ŸŽ€)


๐ŸŒˆ Example ๐ŸŒˆ

// Run this code

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

int main()
{
    wchar_t c = L'\u0b83'; // Tamil sign Visarga ('เฎƒ')

    std::cout << std::hex << std::showbase << std::boolalpha;
    std::cout << "in the default locale, iswalpha(" << (std::wint_t)c
              << ") = "
              << (bool)std::iswalpha(c) << '\n';

    std::setlocale(LC_ALL, "en_US.utf8");
    std::cout << "in Unicode locale, iswalpha(" << (std::wint_t)c << ") = "
              << (bool)std::iswalpha(c) << '\n';
}

Possible output:

in the default locale, iswalpha(0xb83) = false
in Unicode locale, iswalpha(0xb83) = true

๐Ÿ‘‘ See also ๐Ÿ‘‘

  • isalpha(std::locale) โ€” checks if a character is classified as alphabetic by a locale (function template)
  • isalpha โ€” checks if a character is alphabetic (function)
  • C documentation for iswalpha

And then there's this giant ASCII values chart, and I'm keeping every single row because that's the assignment. It's giving chaos, but every value is here:

               ASCII values            characters    iscntrl  isprint  isspace
       isblank  isgraph  ispunct  isalnum  isalpha  isupper  islower  isdigit
       isxdigit decimal hexadecimal   octal                   iswcntrl iswprint
       iswspace iswblank iswgraph iswpunct iswalnum iswalpha iswupper iswlower
       iswdigit iswxdigit 0โ€“8     \x0โ€“\x8     \0โ€“\10    control codes   โ‰ 0
       0        0        0        0        0        0        0        0
       0        0        0
                                     (NUL, etc.)  9       \x9         \11
       tab (\t)        โ‰ 0       0        โ‰ 0       โ‰ 0       0        0        0
       0        0        0        0        0
                                     whitespaces 10โ€“13   \xAโ€“\xD     \12โ€“\15
       (\n, \v, \f,    โ‰ 0       0        โ‰ 0       0        0        0        0
       0        0        0        0        0
                                     \r) 14โ€“31   \xEโ€“\x1F    \16โ€“\37   control
       codes   โ‰ 0       0        0        0        0        0        0        0
       0        0        0        0 32      \x20        \40       space
       0        โ‰ 0       โ‰ 0       โ‰ 0       0        0        0        0
       0        0        0        0 33โ€“47   \x21โ€“\x2F   \41โ€“\57
       !"#$%&'()*+,-./ 0        โ‰ 0       0        0        โ‰ 0       โ‰ 0       0
       0        0        0        0        0 48โ€“57   \x30โ€“\x39   \60โ€“\71
       0123456789      0        โ‰ 0       0        0        โ‰ 0       0        โ‰ 0
       0        0        0        โ‰ 0       โ‰ 0 58โ€“64   \x3Aโ€“\x40   \72โ€“\100
       :;<=>?@         0        โ‰ 0       0        0        โ‰ 0       โ‰ 0       0
       0        0        0        0        0 65โ€“70   \x41โ€“\x46   \101โ€“\106
       ABCDEF          0        โ‰ 0       0        0        โ‰ 0       0        โ‰ 0
       โ‰ 0       โ‰ 0       0        0        โ‰ 0 71โ€“90   \x47โ€“\x5A   \107โ€“\132
       GHIJKLMNOP      0        โ‰ 0       0        0        โ‰ 0       0        โ‰ 0
       โ‰ 0       โ‰ 0       0        0        0
                                     QRSTUVWXYZ 91โ€“96   \x5Bโ€“\x60   \133โ€“\140
       [\]^_`          0        โ‰ 0       0        0        โ‰ 0       โ‰ 0       0
       0        0        0        0        0 97โ€“102  \x61โ€“\x66   \141โ€“\146
       abcdef          0        โ‰ 0       0        0        โ‰ 0       0        โ‰ 0
       โ‰ 0       0        โ‰ 0       0        โ‰ 0 103โ€“122 \x67โ€“\x7A   \147โ€“\172
       ghijklmnop      0        โ‰ 0       0        0        โ‰ 0       0        โ‰ 0
       โ‰ 0       0        โ‰ 0       0        0
                                     qrstuvwxyz 123โ€“126 \x7Bโ€“\x7E   \172โ€“\176
       {|}~            0        โ‰ 0       0        0        โ‰ 0       โ‰ 0       0
       0        0        0        0        0 127     \x7F        \177
       backspace       โ‰ 0       0        0        0        0        0        0
       0        0        0        0        0
                                     character (DEL)

Okay that's the whole page, bestie. Footer realness, because we do not skip the boring bits: source/version is http://cppreference.com, date is 2024.06.10, and the manual page is std::iswalpha(3). Mwah ๐Ÿ’‹โœจ

๐Ÿ“ฆ where this page comes from