Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/locale/ispunct"

From cppreference.com
< cpp‎ | locale
m (changed character in the example for better browser suppport)
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/sidebar}}
+
{{cpp/locale/navbar}}
 
+
{{ddcl|header=locale|
{{ddcl | header=locale |
+
template< class CharT >
template< class charT >
+
bool ispunct( CharT ch, const locale& loc );
bool ispunct( charT ch, const locale& loc );
+
 
}}
 
}}
  
Checks if the given character is classified as an punctuation character by the given locale's {{cpp|std::ctype}} facet.
+
Checks if the given character is classified as a punctuation character by the given locale's {{lc|std::ctype}} facet.
  
 
===Parameters===
 
===Parameters===
{{param list begin}}
+
{{par begin}}
{{param list item | ch | character}}
+
{{par|ch|character}}
{{param list item | loc | locale }}
+
{{par|loc|locale}}
{{param list end}}
+
{{par end}}
  
 
===Return value===
 
===Return value===
 +
Returns {{c|true}} if the character is classified as punctuation, {{c|false}} otherwise.
  
Returns {{cpp|true}} if the character is classified as punctuation, {{cpp|false}} otherwise.
+
===Possible implementation===
 
+
{{eq fun
===Equivalent function===
+
|1=
{{eq fun cpp
+
template<class CharT>
| 1=
+
bool ispunct(CharT ch, const std::locale& loc)
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);
     return std::use_facet<std::ctype<charT>>(loc).is(std::ctype_base::punct, ch);
+
 
}
 
}
 
}}
 
}}
  
 
===Example===
 
===Example===
{{example cpp
+
{{example
| Demonstrates the use of ispunct() with different locales (OS-specific).
+
|Demonstrates the use of {{tt|std::ispunct()}} with different locales (OS-specific).
| code=
+
|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::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';
 
}
 
}
| output=
+
|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===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list template | cpp/string/narrow/dcl list ispunct}}
+
{{dsc inc|cpp/string/byte/dsc ispunct}}
{{dcl list template | cpp/string/wide/dcl list iswpunct}}
+
{{dsc inc|cpp/string/wide/dsc iswpunct}}
{{dcl list end}}
+
{{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).

#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) [edit]
checks if a wide character is a punctuation character
(function) [edit]