Difference between revisions of "cpp/locale/islower"
From cppreference.com
m (r2.7.3) (Robot: Adding de, es, fr, it, ja, pt, ru, zh) |
m (→Example: Use Unicode/C++23 name for 'π' (i.e. capitalized), + `islower` VS `isupper`.) |
||
(6 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | {{cpp/title | islower{{small|(std::locale)}}}} | + | {{cpp/title|islower{{small|(std::locale)}}}} |
{{cpp/locale/navbar}} | {{cpp/locale/navbar}} | ||
− | + | {{ddcl|header=locale| | |
− | {{ddcl | header=locale | | + | template< class CharT > |
− | template< class | + | bool islower( CharT ch, const locale& loc ); |
− | bool islower( | + | |
}} | }} | ||
− | + | Checks if the given character is classified as a lowercase alphabetic character by the given locale's {{lc|std::ctype}} facet. | |
− | + | ||
− | Checks if the given character classified as a lowercase alphabetic character by the given locale's {{ | + | |
===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 lowercase, {{c|false}} otherwise. | Returns {{c|true}} if the character is classified as lowercase, {{c|false}} otherwise. | ||
===Possible implementation=== | ===Possible implementation=== | ||
{{eq fun | {{eq fun | ||
− | + | |1= | |
− | template< class | + | template<class CharT> |
− | bool islower( | + | bool islower(CharT ch, const std::locale& loc) |
− | return std::use_facet<std::ctype< | + | { |
+ | return std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::lower, ch); | ||
} | } | ||
}} | }} | ||
Line 31: | Line 28: | ||
===Example=== | ===Example=== | ||
{{example | {{example | ||
− | + | |Demonstrates the use of {{tt|islower()}} with different locales (OS-specific). | |
− | + | |code= | |
#include <iostream> | #include <iostream> | ||
#include <locale> | #include <locale> | ||
+ | |||
int main() | int main() | ||
{ | { | ||
− | const wchar_t c = L'\u03c0'; // | + | const wchar_t c = L'\u03c0'; // GREEK SMALL LETTER PI |
− | + | ||
std::locale loc1("C"); | std::locale loc1("C"); | ||
− | std::cout << "islower(' | + | std::cout << std::boolalpha |
− | + | << "islower('π', C locale) returned " | |
− | + | << std::islower(c, loc1) << '\n' | |
+ | << "isupper('π', C locale) returned " | ||
+ | << std::isupper(c, loc1) << '\n'; | ||
+ | |||
std::locale loc2("en_US.UTF8"); | std::locale loc2("en_US.UTF8"); | ||
− | std::cout << "islower(' | + | std::cout << "islower('π', Unicode locale) returned " |
− | << std:: | + | << std::islower(c, loc2) << '\n' |
+ | << "isupper('π', Unicode locale) returned " | ||
+ | << std::isupper(c, loc2) << '\n'; | ||
} | } | ||
− | + | |p=true | |
− | islower(' | + | |output= |
− | islower(' | + | islower('π', C locale) returned false |
+ | isupper('π', C locale) returned false | ||
+ | islower('π', Unicode locale) returned true | ||
+ | isupper('π', Unicode locale) returned false | ||
}} | }} | ||
===See also=== | ===See also=== | ||
− | {{ | + | {{dsc begin}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc islower}} |
− | {{ | + | {{dsc inc|cpp/string/wide/dsc iswlower}} |
− | {{ | + | {{dsc end}} |
− | + | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
Latest revision as of 05:59, 4 October 2023
Defined in header <locale>
|
||
template< class CharT > bool islower( CharT ch, const locale& loc ); |
||
Checks if the given character is classified as a lowercase 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 lowercase, false otherwise.
[edit] Possible implementation
template<class CharT> bool islower(CharT ch, const std::locale& loc) { return std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::lower, ch); } |
[edit] Example
Demonstrates the use of islower()
with different locales (OS-specific).
Run this code
#include <iostream> #include <locale> int main() { const wchar_t c = L'\u03c0'; // GREEK SMALL LETTER PI std::locale loc1("C"); std::cout << std::boolalpha << "islower('π', C locale) returned " << std::islower(c, loc1) << '\n' << "isupper('π', C locale) returned " << std::isupper(c, loc1) << '\n'; std::locale loc2("en_US.UTF8"); std::cout << "islower('π', Unicode locale) returned " << std::islower(c, loc2) << '\n' << "isupper('π', Unicode locale) returned " << std::isupper(c, loc2) << '\n'; }
Possible output:
islower('π', C locale) returned false isupper('π', C locale) returned false islower('π', Unicode locale) returned true isupper('π', Unicode locale) returned false
[edit] See also
checks if a character is lowercase (function) | |
checks if a wide character is lowercase (function) |