std::isspace(3)
πΈ std::isspace(3) πΈ
ok so this page is std::isspace, from the C++ Standard Libary manual (yes that's how it's spelled in the source, i'm not touching it π
), manual section 3. it's literally named after itself, main character energy only.
β¨ NAME β¨
std::isspace β std::isspace. that's it. that's the name. iconic of it honestly.
π¦ Synopsis π¦
Defined in header <cctype>
int isspace( int ch );
so the whole vibe is: it checks if the character you handed it is a whitespace character as classified by the currently installed C locale. π«Ά
and in the default locale, the whitespace characters are exactly these six:
- space (
0x20,' ') - form feed (
0x0c,'\f') - line feed (
0x0a,'\n') - carriage return (
0x0d,'\r') - horizontal tab (
0x09,'\t') - vertical tab (
0x0b,'\v')
β οΈ and listen. the behavior is undefined if the value ofchis not representable asunsigned charand is not equal toEOF. like, undefined undefined. do not test it, bestie π
π Parameters π
chβ the character to classify. that's the whole job. give it a char, get a verdict.
β Return value β
- Non-zero value if the character is a whitespace character π
- zero otherwise π
that's the entire contract, no notes.
π₯ Notes π₯
like all the other functions from <cctype>, the behavior of std::isspace 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:
bool my_isspace(char ch)
{
return std::isspace(static_cast<unsigned char>(ch));
}
same energy for standard algorithms β do not use them directly when the iterator's value type is char or signed char. convert the value to unsigned char first, like this:
int count_spaces(const std::string& s)
{
return std::count_if(s.begin(), s.end(),
// static_cast<int(*)(int)>(std::isspace) // wrong
// [](int c){ return std::isspace(c); } // wrong
// [](char c){ return std::isspace(c); } // wrong
[](unsigned char c){ return std::isspace(c); } // correct
);
}
π§ the vibe check table (no cap) π§
the source lays out an ASCII values table whose header lists the columns as:
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
each row below carries twelve values, in that header order: iscntrl, isprint, isspace, isblank, isgraph, ispunct, isalnum, isalpha, isupper, islower, isdigit, isxdigit. (the wide twins iswcntrl β¦ iswxdigit are named in the header too, k? π)
- ASCII
0β8β decimal0β8, hex\x0β\x8, octal\0β\10β control codes (NUL, etc.) ββ 0 0 0 0 0 0 0 0 0 0 0 0 - ASCII
9β decimal9, hex\x9, octal\11β tab (\t), whitespaces ββ 0 0 β 0 β 0 0 0 0 0 0 0 0 0 - ASCII
10β13β decimal10β13, hex\xAβ\xD, octal\12β\15β\n,\v,\f,\rββ 0 0 β 0 0 0 0 0 0 0 0 0 0 - ASCII
14β31β decimal14β31, hex\xEβ\x1F, octal\16β\37β control codes ββ 0 0 0 0 0 0 0 0 0 0 0 0 - ASCII
32β decimal32, hex\x20, octal\40β space β0 β 0 β 0 β 0 0 0 0 0 0 0 0 0 - ASCII
33β47β decimal33β47, hex\x21β\x2F, octal\41β\57β!"#$%&'()*+,-./β0 β 0 0 0 β 0 β 0 0 0 0 0 0 0 - ASCII
48β57β decimal48β57, hex\x30β\x39, octal\60β\71β0123456789β0 β 0 0 0 β 0 0 β 0 0 0 0 β 0 β 0 - ASCII
58β64β decimal58β64, hex\x3Aβ\x40, octal\72β\100β:;<=>?@β0 β 0 0 0 β 0 β 0 0 0 0 0 0 0 - ASCII
65β70β decimal65β70, hex\x41β\x46, octal\101β\106βABCDEFβ0 β 0 0 0 β 0 0 β 0 β 0 β 0 0 0 β 0 - ASCII
71β90β decimal71β90, hex\x47β\x5A, octal\107β\132βGHIJKLMNOPQRSTUVWXYZβ0 β 0 0 0 β 0 0 β 0 β 0 β 0 0 0 0 - ASCII
91β96β decimal91β96, hex\x5Bβ\x60, octal\133β\140β[\]^_\`` β0 β 0 0 0 β 0 β 0 0 0 0 0 0 0` - ASCII
97β102β decimal97β102, hex\x61β\x66, octal\141β\146βabcdefβ0 β 0 0 0 β 0 0 β 0 β 0 0 β 0 0 β 0 - ASCII
103β122β decimal103β122, hex\x67β\x7A, octal\147β\172βghijklmnopqrstuvwxyzβ0 β 0 0 0 β 0 0 β 0 β 0 0 β 0 0 0 - ASCII
123β126β decimal123β126, hex\x7Bβ\x7E, octal\172β\176β{|}~β0 β 0 0 0 β 0 β 0 0 0 0 0 0 0 - ASCII
127β decimal127, hex\x7F, octal\177β backspace character (DEL) ββ 0 0 0 0 0 0 0 0 0 0 0 0
π See also π
isspace(std::locale)β checks if a character is classified as whitespace by a locale (function template)iswspaceβ checks if a wide character is a space character (function)- C documentation for
isspace
ok that's the whole page bestie, you're soooo ready for your locale questions now πβ¨
sign-off: this absolute gem comes from http://cppreference.com, dated 2024.06.10, and it's page std::isspace(3) β go forth and static_cast<unsigned char> everything π«Άππ
π¦ 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