std::isblank(std::locale)(3)

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

πŸ’– NAME πŸ’–

std::isblank(std::locale) - std::isblank(std::locale)

Okay bestie, this is the std::isblank(std::locale)(3) page from the C++ Standard Libary manual (yes, β€œLibary” with one r in the header, we respect the lore πŸ’…). It’s the locale-aware blank-character check, and it’s lowkey iconic.


πŸ“ Synopsis πŸ“

Defined in header <locale>

template< class CharT >                       (since C++11)
bool isblank( CharT ch, const locale& loc );

So what does it do? It checks if the given character is classified as a blank character by the given locale’s std::ctype facet. That’s the whole vibe check. ✨


🌸 Parameters 🌸

  • ch β€” character
  • loc β€” locale

🫢 Return value 🫢

Returns true if the character is classified as a blank character, false otherwise. No cap, that’s it. πŸ’–


🧚 Possible implementation 🧚

Here’s a possible implementation, like a fan recreation of the function’s fit:

template<class CharT>
bool isblank(CharT ch, const std::locale& loc)
{
    return std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::blank, ch);
}

✨ Example ✨

Demonstrates the use of isblank() with different locales (OS-specific).

The page has a lil // Run this code note before the snippet, so here’s the code in all its glory:

#include <iostream>
#include <locale>

void try_with(wchar_t c, const char* loc)
{
    std::wcout << "isblank('" << c << "', locale(\"" << loc << "\")) returned "
               << std::boolalpha
               << std::isblank(c, std::locale(loc)) << '\n';
}

int main()
{
    const wchar_t IDEO_SPACE = L'\u3000'; // Unicode character 'IDEOGRAPHIC SPACE'
    try_with(IDEO_SPACE, "C");
    try_with(IDEO_SPACE, "en_US.UTF-8");
}

πŸ’… Possible output πŸ’…

That gap inside the quotes is the IDEO_SPACE from the example, bestie β€” the ideographic space is serving looks:

isblank('γ€€', locale("C")) returned false
isblank('γ€€', locale("en_US.UTF-8")) returned true

πŸ”₯ See also πŸ”₯

  • isblank β€” checks if a character is a blank character; (C++11) (function)
  • iswblank β€” checks if a wide character is a blank character; (C++11) (function)

That’s the whole vibe check, bestie. This page came from http://cppreference.com, dated 2024.06.10, and it’s filed under std::isblank(std::locale)(3). Go classify some blanks with your favorite locale, mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from