Difference between revisions of "cpp/locale/ispunct"
From cppreference.com
m (changed character in the example for better browser suppport) |
Andreas Krug (Talk | contribs) m (fmt) |
||
(11 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | {{cpp/title | ispunct{{small|(std::locale)}}}} | + | {{cpp/title|ispunct{{small|(std::locale)}}}} |
− | {{cpp/locale/ | + | {{cpp/locale/navbar}} |
− | + | {{ddcl|header=locale| | |
− | {{ddcl | header=locale | | + | template< class CharT > |
− | template< class | + | bool ispunct( CharT ch, const locale& loc ); |
− | bool ispunct( | + | |
}} | }} | ||
− | Checks if the given character is classified as | + | Checks if the given character is classified as a punctuation character by the given locale's {{lc|std::ctype}} facet. |
===Parameters=== | ===Parameters=== | ||
− | {{ | + | {{par begin}} |
− | {{ | + | {{par|ch|character}} |
− | {{ | + | {{par|loc|locale}} |
− | {{ | + | {{par end}} |
===Return value=== | ===Return value=== | ||
+ | Returns {{c|true}} if the character is classified as punctuation, {{c|false}} otherwise. | ||
− | + | ===Possible implementation=== | |
− | + | {{eq fun | |
− | === | + | |1= |
− | {{eq fun | + | template<class CharT> |
− | + | bool ispunct(CharT ch, const std::locale& loc) | |
− | template< class | + | { |
− | bool ispunct( | + | return std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::punct, ch); |
− | return std::use_facet<std::ctype< | + | |
} | } | ||
}} | }} | ||
===Example=== | ===Example=== | ||
− | {{example | + | {{example |
− | + | |Demonstrates the use of {{tt|std::ispunct()}} with different locales (OS-specific). | |
− | + | |code= | |
#include <iostream> | #include <iostream> | ||
#include <locale> | #include <locale> | ||
+ | |||
int main() | int main() | ||
{ | { | ||
Line 40: | Line 40: | ||
std::locale loc1("C"); | std::locale loc1("C"); | ||
std::cout << "ispunct('⅋', C locale) returned " | std::cout << "ispunct('⅋', C locale) returned " | ||
− | + | << std::boolalpha << std::ispunct(c, loc1) << '\n'; | |
std::locale loc2("en_US.UTF-8"); | std::locale loc2("en_US.UTF-8"); | ||
Line 46: | Line 46: | ||
<< std::boolalpha << std::ispunct(c, loc2) << '\n'; | << std::boolalpha << std::ispunct(c, loc2) << '\n'; | ||
} | } | ||
− | + | |p=true | |
+ | |output= | ||
isalpha('⅋', C locale) returned false | isalpha('⅋', C locale) returned false | ||
isalpha('⅋', Unicode locale) returned true | isalpha('⅋', Unicode locale) returned true | ||
Line 52: | Line 53: | ||
===See also=== | ===See also=== | ||
− | {{ | + | {{dsc begin}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc ispunct}} |
− | {{ | + | {{dsc inc|cpp/string/wide/dsc iswpunct}} |
− | {{ | + | {{dsc end}} |
+ | |||
+ | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} |
Latest revision as of 10:32, 3 October 2023
Defined in header <locale>
|
||
template< class CharT > bool ispunct( CharT ch, const locale& loc ); |
||
Checks if the given character is classified as a punctuation character by the given locale's std::ctype facet.
Contents |
[edit] Parameters
ch | - | character |
loc | - | locale |
[edit] Return value
Returns true if the character is classified as punctuation, false otherwise.
[edit] Possible implementation
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); } |
[edit] Example
Demonstrates the use of std::ispunct()
with different locales (OS-specific).
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
[edit] See also
checks if a character is a punctuation character (function) | |
checks if a wide character is a punctuation character (function) |