std::isspace(std::locale)(3)
π std::isspace(std::locale)(3) π
okay so bestie, welcome to the C++ Standard Libary manual, section 3 β yes that's how they spell it, don't come for me, i'm just the messenger π this page is literally all about std::isspace(std::locale) and it's giving "tiny function, big feelings."
β¨ NAME β¨
std::isspace(std::locale) β literally just std::isspace(std::locale), that's the whole name, she's not hiding anything π
πΈ Synopsis πΈ
first things first, she lives in this header, no cap:
Defined in header <locale>
and here's her whole signature, character for character:
template< class CharT >
bool isspace( CharT ch, const locale& loc );
so what does she do?? she checks if the given character is classified as a whitespace character by the given locale's std::ctype facet π¦ that's it, that's the vibe check.
π Parameters π
chβ the character. your lil guy. the one getting checked πlocβ the locale. the whole cultural context deciding whether your character counts as space or not, iconic behavior honestly
π Return value π
returns true if the character is classified as a whitespace character, and false otherwise β¨ simple! clean! no drama!
π§ Possible implementation π§
here's how she could be built under the hood, and honestly it's giving one-liner main character energy:
template<class CharT>
bool isspace(CharT ch, const std::locale& loc)
{
return std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::space, ch);
}
π Example π
this one demonstrates std::isspace() with different locales, and heads up β it's OS-specific, so your mileage may absolutely vary π«Ά
the page literally has a // Run this code button above this bad boy, that's the cppreference special
#include <iostream>
#include <locale>
void try_with(wchar_t c, const char* loc)
{
std::wcout << "isspace('" << c << "', locale(\"" << loc << "\")) returned "
<< std::boolalpha << std::isspace(c, std::locale(loc)) << '\n';
}
int main()
{
const wchar_t EM_SPACE = L'\u2003'; // Unicode character 'EM SPACE'
try_with(EM_SPACE, "C");
try_with(EM_SPACE, "en_US.UTF8");
}
β Possible output β
look at this little glow-up between locales, we love to see it:
isspace(' ', locale("C")) returned false
isspace(' ', locale("en_US.UTF8")) returned true
likeβ¦ the C locale said "not my problem" and en_US.UTF8 said "oh she's space space" πβ¨
π¦ See also π¦
isspaceβ checks if a character is a space character (function) πiswspaceβ checks if a wide character is a space character (function) π«
okay that's the whole page, you're basically a locale expert now, no cap π β¨
sign-off time bestie: this lil beauty lives over at http://cppreference.com, dated 2024.06.10, and she's filed under std::isspace(std::locale)(3) β mwah, go forth and check your whitespace ππ«Άπ
π¦ 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