Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/locale/isalpha"

From cppreference.com
< cpp‎ | locale
m (remove zero-width space)
m (trim spaces; chart→CharT, langlinks)
Line 1: Line 1:
{{cpp/title | isalpha{{small|(std::locale)}}}}
+
{{cpp/title|isalpha{{small|(std::locale)}}}}
 
{{cpp/locale/navbar}}
 
{{cpp/locale/navbar}}
 
+
{{ddcl|header=locale|
{{ddcl | header=locale |
+
template< class CharT >
template< class charT >
+
bool isalpha( CharT ch, const locale& loc );
bool isalpha( charT ch, const locale& loc );
+
 
}}
 
}}
  
Line 11: Line 10:
 
===Parameters===
 
===Parameters===
 
{{par begin}}
 
{{par begin}}
{{par | ch | character}}
+
{{par|ch|character}}
{{par | loc | locale }}
+
{{par|loc|locale }}
 
{{par end}}
 
{{par end}}
  
 
===Return value===
 
===Return value===
 
 
Returns {{c|true}} if the character is classified as alphabetic, {{c|false}} otherwise.
 
Returns {{c|true}} if the character is classified as alphabetic, {{c|false}} otherwise.
  
 
===Possible implementation===
 
===Possible implementation===
 
{{eq fun
 
{{eq fun
| 1=
+
|1=
template< class charT >
+
template< class CharT >
bool isalpha( charT ch, const std::locale& loc ) {
+
bool isalpha( CharT ch, const std::locale& loc ) {
     return std::use_facet<std::ctype<charT>>(loc).is(std::ctype_base::alpha, ch);
+
     return std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::alpha, ch);
 
}
 
}
 
}}
 
}}
Line 30: Line 28:
 
===Example===
 
===Example===
 
{{example
 
{{example
| Demonstrates the use of isalpha() with different locales (OS-specific).
+
|Demonstrates the use of isalpha() with different locales (OS-specific).
| code=
+
|code=
 
#include <iostream>
 
#include <iostream>
 
#include <locale>
 
#include <locale>
 +
 
int main()
 
int main()
 
{
 
{
Line 46: Line 45:
 
               << std::boolalpha << std::isalpha(c, loc2) << '\n';
 
               << std::boolalpha << std::isalpha(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 53: Line 53:
 
===See also===
 
===See also===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/string/byte/dsc isalpha}}
+
{{dsc inc|cpp/string/byte/dsc isalpha}}
{{dsc inc | cpp/string/wide/dsc iswalpha}}
+
{{dsc inc|cpp/string/wide/dsc iswalpha}}
 
{{dsc end}}
 
{{dsc end}}
  
[[de:cpp/locale/isalpha]]
+
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}
[[es:cpp/locale/isalpha]]
+
[[fr:cpp/locale/isalpha]]
+
[[it:cpp/locale/isalpha]]
+
[[ja:cpp/locale/isalpha]]
+
[[pt:cpp/locale/isalpha]]
+
[[ru:cpp/locale/isalpha]]
+
[[zh:cpp/locale/isalpha]]
+

Revision as of 15:06, 23 January 2023

 
 
 
Defined in header <locale>
template< class CharT >
bool isalpha( CharT ch, const locale& loc );

Checks if the given character is classified as an alphabetic character by the given locale's std::ctype facet.

Contents

Parameters

ch - character
loc - locale

Return value

Returns true if the character is classified as alphabetic, false otherwise.

Possible implementation

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

Example

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

#include <iostream>
#include <locale>
 
int main()
{
    const wchar_t c = L'\u042f'; // cyrillic capital letter ya
 
    std::locale loc1("C");
    std::cout << "isalpha('Я', C locale) returned "
               << std::boolalpha << std::isalpha(c, loc1) << '\n';
 
    std::locale loc2("en_US.UTF8");
    std::cout << "isalpha('Я', Unicode locale) returned "
              << std::boolalpha << std::isalpha(c, loc2) << '\n';
}

Possible output:

isalpha('Я', C locale) returned false
isalpha('Я', Unicode locale) returned true

See also

checks if a character is alphabetic
(function) [edit]
checks if a wide character is alphabetic
(function) [edit]