std::ctype:...type::do_is(3)
π NAME π
okay bestie, this is std::ctype::is and std::ctype::do_is β and yes, the NAME is literally std::ctype::is,std::ctype::do_is - std::ctype::is,std::ctype::do_is, twice, because the manpage said it and we're keeping the receipts π
. It comes from the C++ Standard Libary manual, page id std::ctype:...type::do_is(3). We're so back.
β¨ 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:
virtual const CharT* do_is( const CharT* low, const CharT* high,
mask* vec ) (4)
const;
okay so what's the tea:
1,2)β Public member function, calls the protected virtual member functiondo_isof the most derived class.3)β Checks if the charactercis classified by the maskm.4)β For every character in the character array[low, high), identifies the complete classification mask (e.g.digit|xdigit|alnum|print|graphfor the digit'0'in the default locale), and stores the masks in the corresponding elements of the array pointed to byvec.
πΈ Parameters πΈ
cβ character to classifymβ mask to use for classifying a single characterlowβ pointer to the first character in an array of characters to classifyhighβ one past the end pointer for the array of characters to classifyvecβ pointer to the first element of the array of masks to fill
π Return value π
1,3)βtrueifcis classified bym.2,4)βhigh
π§ Example π§
Run this code, bestie β exact example, no cap:
#include <cstddef>
#include <iostream>
#include <locale>
#include <utility>
#include <vector>
// 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+" << static_cast<wint_t>(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 π¦
isβ classifies a character or a character sequence, using the classification table (public member function ofstd::ctype<char>)iswctypeβ classifies a wide character according to the specifiedLC_CTYPEcategory (function)
source: http://cppreference.com Β· version/page: std::ctype:...type::do_is(3) Β· date: 2024.06.10 π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms