Difference between revisions of "cpp/locale/isspace"
From cppreference.com
m (comment) |
Andreas Krug (Talk | contribs) m (fmt) |
||
(14 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
− | {{cpp/title | isspace{{small|(std::locale)}}}} | + | {{cpp/title|isspace{{small|(std::locale)}}}} |
− | {{cpp/locale/ | + | {{cpp/locale/navbar}} |
− | + | {{ddcl|header=locale| | |
− | {{ddcl | header=locale | | + | template< class CharT > |
− | template< class | + | bool isspace( CharT ch, const locale& loc ); |
− | bool isspace( | + | |
}} | }} | ||
− | + | Checks if the given character is classified as a whitespace character by the given locale's {{lc|std::ctype}} facet. | |
− | Checks if the given character classified as a whitespace character by the given locale's 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 a whitespace character, {{c|false}} otherwise. | ||
− | + | ===Possible implementation=== | |
− | + | {{eq fun | |
− | === | + | |1= |
− | {{eq fun | + | template<class CharT> |
− | + | bool isspace(CharT ch, const std::locale& loc) | |
− | template< class | + | { |
− | bool isspace( | + | return std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::space, ch); |
− | return std::use_facet<std::ctype< | + | |
} | } | ||
}} | }} | ||
===Example=== | ===Example=== | ||
− | {{example | + | {{example |
− | + | |Demonstrates the use of {{tt|std::isspace()}} with different locales (OS-specific). | |
− | + | |code= | |
#include <iostream> | #include <iostream> | ||
#include <locale> | #include <locale> | ||
+ | |||
void try_with(wchar_t c, const char* loc) | void try_with(wchar_t c, const char* loc) | ||
{ | { | ||
− | std::wcout << "isspace('" << c << "', locale(\"" << loc << "\")) returned " << std::boolalpha | + | std::wcout << "isspace('" << c << "', locale(\"" << loc << "\")) returned " |
− | + | << std::boolalpha << std::isspace(c, std::locale(loc)) << '\n'; | |
} | } | ||
+ | |||
int main() | int main() | ||
{ | { | ||
Line 46: | Line 46: | ||
try_with(EM_SPACE, "en_US.UTF8"); | try_with(EM_SPACE, "en_US.UTF8"); | ||
} | } | ||
− | + | |p=true | |
+ | |output= | ||
isspace(' ', locale("C")) returned false | isspace(' ', locale("C")) returned false | ||
isspace(' ', locale("en_US.UTF8")) returned true | isspace(' ', locale("en_US.UTF8")) returned true | ||
Line 52: | Line 53: | ||
===See also=== | ===See also=== | ||
− | {{ | + | {{dsc begin}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc isspace}} |
− | {{ | + | {{dsc inc|cpp/string/wide/dsc iswspace}} |
− | {{ | + | {{dsc end}} |
+ | |||
+ | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} |
Latest revision as of 10:33, 3 October 2023
Defined in header <locale>
|
||
template< class CharT > bool isspace( CharT ch, const locale& loc ); |
||
Checks if the given character is classified as a whitespace 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 a whitespace character, false otherwise.
[edit] Possible implementation
template<class CharT> bool isspace(CharT ch, const std::locale& loc) { return std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::space, ch); } |
[edit] Example
Demonstrates the use of std::isspace()
with different locales (OS-specific).
Run this code
#include <iostream> #include <locale> void try_with(wchar_t c, const char* loc) { std::wcout << "isspace('" << c << "', locale(\"" << loc << "\")) returned " << std::boolalpha << std::isspace(c, std::locale(loc)) << '\n'; } int main() { const wchar_t EM_SPACE = L'\u2003'; // Unicode character 'EM SPACE' try_with(EM_SPACE, "C"); try_with(EM_SPACE, "en_US.UTF8"); }
Possible output:
isspace(' ', locale("C")) returned false isspace(' ', locale("en_US.UTF8")) returned true
[edit] See also
checks if a character is a space character (function) | |
checks if a wide character is a space character (function) |