Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/locale/isspace"

From cppreference.com
< cpp‎ | locale
m (Text replace - "cpp/string/narrow" to "cpp/string/byte")
m (fmt)
 
(13 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/sidebar}}
+
{{cpp/locale/navbar}}
 
+
{{ddcl|header=locale|
{{ddcl | header=locale |
+
template< class CharT >
template< class charT >
+
bool isspace( CharT ch, const locale& loc );
bool isspace( charT ch, const locale& loc );
+
 
}}
 
}}
  
 
+
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===
{{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 a whitespace character, {{c|false}} otherwise.
  
Returns {{cpp|true}} if the character is classified as a whitespace character, {{cpp|false}} otherwise.
+
===Possible implementation===
 
+
{{eq fun
===Equivalent function===
+
|1=
{{eq fun cpp
+
template<class CharT>
| 1=
+
bool isspace(CharT ch, const std::locale& loc)
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);
     return std::use_facet<std::ctype<charT>>(loc).is(std::ctype_base::space, ch);
+
 
}
 
}
 
}}
 
}}
  
 
===Example===
 
===Example===
{{example cpp
+
{{example
| Demonstrates the use of isspace() with different locales (OS-specific).
+
|Demonstrates the use of {{tt|std::isspace()}} with different locales (OS-specific).
| code=
+
|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::isspace(c, std::locale(loc)) << '\n';
+
              << 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");
 
}
 
}
| output=
+
|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===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list template | cpp/string/byte/dcl list isspace}}
+
{{dsc inc|cpp/string/byte/dsc isspace}}
{{dcl list template | cpp/string/wide/dcl list iswspace}}
+
{{dsc inc|cpp/string/wide/dsc iswspace}}
{{dcl list end}}
+
{{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).

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