std::ctype<CharT>::is,std::ctype<CharT>::do_is (3) - Linux Manuals
std::ctype<CharT>::is,std::ctype<CharT>::do_is: std::ctype<CharT>::is,std::ctype<CharT>::do_is
Command to display std::ctype<CharT>::is,std::ctype<CharT>::do_is
manual in Linux: $ man 3 std::ctype<CharT>::is,std::ctype<CharT>::do_is
NAME
std::ctype<CharT>::is,std::ctype<CharT>::do_is - std::ctype<CharT>::is,std::ctype<CharT>::do_is
Synopsis
Defined in header <locale>
public: (1)
bool is(mask m, CharT c) const;
public: (2)
const CharT* is(const CharT* low, const CharT* high, mask* vec) const;
protected: (3)
virtual bool do_is(mask m, CharT c) const;
protected: (4)
virtual const CharT* do_is(const CharT* low, const CharT* high, mask* vec) const;
1,2) public member function, calls the protected virtual member function do_is of the most derived class.
3) Checks if the character c is classified by the mask m
4) For every character in the character array [low, high), identifies the complete classification mask (e.g. digit|xdigit|alnum|print|graph for the digit '0' in the default locale), and stores the masks in the corresponding elements of the array pointed to by vec
Parameters
c - character to classify
m - mask to use for classifying a single character
low - pointer to the first character in an array of characters to classify
high - one past the end pointer for the array of characters to classify
vec - pointer to the first element of the array of masks to fill
Return value
1,3) true if c is classified by m
2,4) high
Example
// Run this code
#include <locale>
#include <utility>
#include <vector>
#include <iostream>
// utility wrapper to make locale-bound facets destructible
template<class Facet>
struct deletable_facet : Facet
{
template<class ...Args>
deletable_facet(Args&& ...args) : Facet(std::forward<Args>(args)...) {}
~deletable_facet() {}
};
int main()
{
// classify a single character using the default locale
auto& f = std::use_facet<std::ctype<char>>(std::locale());
char c = '0';
if (f.is(std::ctype_base::digit, c)) // or isdigit(c, locale());
{
std::cout << "'" << c << "' is a digit\n";
}
// classify every character in a string using a named locale
deletable_facet<std::ctype_byname<wchar_t>> f2("en_US.utf8");
std::wstring str = L"z\u00df\u6c34\U0001d10b";
std::vector<std::ctype_base::mask> vec(str.size());
f2.is(&str[0], &str[0] + str.size(), &vec[0]);
for (std::size_t n = 0; n < str.size(); ++n) {
std::cout << std::hex << "U+" << str[n] << " is: ";
if (vec[n] & std::ctype_base::alnum)
std::cout << " alnum ";
if (vec[n] & std::ctype_base::punct)
std::cout << " punct ";
std::cout << '\n';
}
}
Output:
'0' is a digit
U+7a is: alnum
U+df is: alnum
U+6c34 is: alnum
U+1d10b is: punct
See also
classifies a character or a character sequence, using the classification table
is (public member function of std::ctype<char>)
classifies a wide character according to the specified LC_CTYPE category
iswctype (function)
Pages related to std::ctype<CharT>::is,std::ctype<CharT>::do_is
- std::ctype<CharT>::ctype (3) - std::ctype<CharT>::ctype
- std::ctype<CharT>::narrow,do_narrow (3) - std::ctype<CharT>::narrow,do_narrow
- std::ctype<CharT>::scan_is,std::ctype<CharT>::do_scan_is (3) - std::ctype<CharT>::scan_is,std::ctype<CharT>::do_scan_is
- std::ctype<CharT>::scan_not,std::ctype<CharT>::do_scan_not (3) - std::ctype<CharT>::scan_not,std::ctype<CharT>::do_scan_not
- std::ctype<CharT>::tolower,std::ctype<CharT>::do_tolower (3) - std::ctype<CharT>::tolower,std::ctype<CharT>::do_tolower
- std::ctype<CharT>::toupper,std::ctype<CharT>::do_toupper (3) - std::ctype<CharT>::toupper,std::ctype<CharT>::do_toupper
- std::ctype<CharT>::widen,do_widen (3) - std::ctype<CharT>::widen,do_widen
- std::ctype<CharT>::~ctype (3) - std::ctype<CharT>::~ctype
- std::ctype<char> (3) - std::ctype<char>
- std::ctype<char>::classic_table (3) - std::ctype<char>::classic_table
- std::ctype<char>::ctype (3) - std::ctype<char>::ctype
- std::ctype<char>::is (3) - std::ctype<char>::is
- std::ctype<char>::scan_is (3) - std::ctype<char>::scan_is
- std::ctype<char>::scan_not (3) - std::ctype<char>::scan_not
- std::ctype<char>::table (3) - std::ctype<char>::table