Difference between revisions of "cpp/locale/isalpha"
From cppreference.com
D41D8CD98F (Talk | contribs) m (remove zero-width space) |
m (→Example: tt) |
||
(3 intermediate revisions by 2 users not shown) | |||
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 | + | bool isalpha( CharT ch, const locale& loc ); |
− | bool isalpha( | + | |
}} | }} | ||
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= | |
− | template< class | + | template<class CharT> |
− | bool isalpha( | + | bool isalpha(CharT ch, const std::locale& loc) |
− | return std::use_facet<std::ctype< | + | { |
+ | return std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::alpha, ch); | ||
} | } | ||
}} | }} | ||
Line 30: | Line 29: | ||
===Example=== | ===Example=== | ||
{{example | {{example | ||
− | + | |Demonstrates the use of {{tt|isalpha()}} 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 << "isalpha('Я', C locale) returned " | std::cout << "isalpha('Я', C locale) returned " | ||
− | + | << std::boolalpha << std::isalpha(c, loc1) << '\n'; | |
std::locale loc2("en_US.UTF8"); | std::locale loc2("en_US.UTF8"); | ||
Line 46: | Line 46: | ||
<< std::boolalpha << std::isalpha(c, loc2) << '\n'; | << std::boolalpha << std::isalpha(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 53: | Line 54: | ||
===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}} | ||
− | + | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
Latest revision as of 07:19, 4 October 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 |
[edit] Parameters
ch | - | character |
loc | - | locale |
[edit] Return value
Returns true if the character is classified as alphabetic, false otherwise.
[edit] 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); } |
[edit] Example
Demonstrates the use of isalpha()
with different locales (OS-specific).
Run this code
#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
[edit] See also
checks if a character is alphabetic (function) | |
checks if a wide character is alphabetic (function) |