std::isblank(3)

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

okay so bestie, welcome to std::isblank(3) πŸ’… β€” yeah, that's the C++ Standard Library section, and this little icon is genuinely obsessed with one (1) question: is this thing a blank character or not? let's get into it πŸŽ€

🌸 NAME 🌸

std::isblank β€” that's it, that's the name. std::isblank is std::isblank. no notes, slay.

✨ SYNOPSIS ✨

Defined in header <cctype>:

int isblank( int ch );

(since C++11) πŸ¦‹

Checks if the given character is a blank character as classified by the currently installed C locale. Blank characters are whitespace characters used to separate words within a sentence. In the default C locale, only space (0x20) and horizontal tab (0x09) are classified as blank characters.

😭 Heads up, and this is the important part: the behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF. Not "kinda weird", not "oopsie" β€” undefined. respect the vibe check fr fr πŸ’€

πŸ¦‹ PARAMETERS πŸ¦‹

  • ch β€” the character to classify. that's the whole gig.

⭐ RETURN VALUE ⭐

Non-zero value if the character is a blank character, zero otherwise. simple as that, iykyk.

πŸ’œ NOTES πŸ’œ

Like all other functions from <cctype>, the behavior of std::isblank is undefined if the argument's value is neither representable as unsigned char nor equal to EOF. So to use these functions safely with plain chars (or signed chars), convert the argument to unsigned char first, bestie 🫢:

bool my_isblank(char ch)
{
    return std::isblank(static_cast<unsigned char>(ch));
}

Similarly, they should not be directly used with standard algorithms when the iterator's value type is char or signed char. Instead, convert the value to unsigned char first:

int count_blanks(const std::string& s)
{
    return std::count_if(s.begin(), s.end(),
                      // static_cast<int(*)(int)>(std::isblank)      // wrong
                      // [](int c){ return std::isblank(c); }        // wrong
                      // [](char c){ return std::isblank(c); }       // wrong
                         [](unsigned char c){ return std::isblank(c); } // correct
                        );
}

like look at those comments β€” three wrongs and one correct. the correct one took the unsigned char route and it ATE ✨

πŸ‘‘ SEE ALSO πŸ‘‘

  • isblank(std::locale) (C++11) β€” checks if a character is classified as a blank character by a locale (function template) 🌈
  • iswblank (C++11) β€” checks if a wide character is a blank character (function) 🌸
  • C documentation for isblank πŸŽ€

🌈 ASCII values 🌈

here's the full chart, because of course there's a full chart 🧚 the flags across the top are: iscntrl, isprint, isspace, isblank, isgraph, ispunct, isalnum, isalpha, isupper, islower, isdigit, isxdigit β€” and the table's wide-character columns are iswcntrl, iswprint, iswspace, iswblank, iswgraph, iswpunct, iswalnum, iswalpha, iswupper, iswlower, iswdigit, iswxdigit πŸ’–

decimal hex      octal    characters               iscntrl isprint isspace isblank isgraph ispunct isalnum isalpha isupper islower isdigit isxdigit
0–8     \x0–\x8  \0–\10   control codes (NUL, etc.) β‰ 0     0      0      0      0      0      0      0      0      0      0      0
9       \x9      \11      tab (\t)                 β‰ 0     0      β‰ 0     β‰ 0     0      0      0      0      0      0      0      0
10–13   \xA–\xD  \12–\15  whitespaces (\n,\v,\f,\r) β‰ 0     0      β‰ 0     0      0      0      0      0      0      0      0      0
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 GHIJKLMNOPQRSTUVWXYZ      0      β‰ 0     0      0      β‰ 0     0      β‰ 0     β‰ 0     β‰ 0     0      0      0
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 ghijklmnopqrstuvwxyz     0      β‰ 0     0      0      β‰ 0     0      β‰ 0     β‰ 0     0      β‰ 0     0      0
123–126 \x7B–\x7E \172–\176 {|}~                     0      β‰ 0     0      0      β‰ 0     β‰ 0     0      0      0      0      0      0
127     \x7F     \177     backspace character (DEL) β‰ 0     0      0      0      0      0      0      0      0      0      0      0

look at that lonely little β‰ 0 in isblank for space and tab. those two are the main characters of this entire manpage πŸ‘‘πŸ’…


and that's the whole thing bestie!! 🫢 this page came from http://cppreference.com, dated 2024.06.10, and yes β€” the page is literally called std::isblank(3), which is honestly iconic of it. mwah πŸ’– go classify some blanks, stay unsigned char, and don't let anyone catch you passing a raw char πŸ˜­βœ¨πŸŽ€

πŸ“¦ where this page comes from