std::ispunct(std::locale)(3)
π
std::ispunct(std::locale)(3) π
Okay bestie, welcome to the C++ Standard Libary manual, section 3 β yes, that's the manual name, typo and all, no cap. Today's main character is the locale-aware punctuation check: std::ispunct(std::locale). It's giving βdoes this character count as punctuation in this locale?β energy, and honestly? Iconic. π
πΈ NAME πΈ
std::ispunct(std::locale) β std::ispunct(std::locale). That's the name, bestie. It's the locale-flavored punctuation checker. Periodt. π
β¨ Synopsis β¨
Defined in header <locale>:
template< class CharT >
bool ispunct( CharT ch, const locale& loc );
So what's the vibe check? It checks if the given character is classified as a punctuation character by the given locale's std::ctype facet. That's the whole assignment. π¦
π Parameters π
chβ characterlocβ locale
π Return value π
Returns true if the character is classified as punctuation, false otherwise. Simple as that, bestie. β¨
π§ Possible implementation π§
Here's how it could look under the hood, fr fr:
template<class CharT>
bool ispunct(CharT ch, const std::locale& loc)
{
return
std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::punct, ch);
}
π Example π
This one demonstrates the use of std::ispunct() with different locales (OS-specific). So yes, your mileage may vary depending on the OS, bestie β it's not me being dramatic, that's literally in the notes. π
// Run this code
#include <iostream>
#include <locale>
int main()
{
const wchar_t c = L'\u214b'; // upside-down ampersand
std::locale loc1("C");
std::cout << "ispunct('β
', C locale) returned "
<< std::boolalpha << std::ispunct(c, loc1) << '\n';
std::locale loc2("en_US.UTF-8");
std::cout << "ispunct('β
', Unicode locale) returned "
<< std::boolalpha << std::ispunct(c, loc2) << '\n';
}
π Possible output π
isalpha('β
', C locale) returned false
isalpha('β
', Unicode locale) returned true
Yes, the output says isalpha while the example calls ispunct β I'm not fixing it, I'm preserving it. The lore is the lore. π
π See also π
ispunctβ checks if a character is a punctuation character (function)iswpunctβ checks if a wide character is a punctuation character (function)
Source/version/date sign-off, bestie: http://cppreference.com Β· 2024.06.10 Β· page std::ispunct(std::locale)(3) πβ¨
π¦ 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