首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::ctype::do_is

Defined in header <locale>

public: bool is(mask m, CharT c) const;

(1)

public: const CharT* is(const CharT* low, const CharT* high, mask* vec) const;

(2)

protected: virtual bool do_is(mask m, CharT c) const;

(3)

protected: virtual const CharT* do_is(const CharT* low, const CharT* high, mask* vec) const;

(4)

1,2%29的公共成员函数,调用受保护的虚拟成员函数。do_is最派生的类。

3%29检查字符是否c按面具分类m

4%29对字符数组中的每个字符[low, high),标识完整的分类掩码%28例如。digit|xdigit|alnum|print|graph数字'0'在默认的locale%29中,并将掩码存储在指向vec

参数

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

返回值

1,3%29true如果cm

2,4%29high

二次

代码语言:javascript
复制
#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';
    }
}

二次

产出:

二次

代码语言:javascript
复制
'0' is a digit
U+7a is:  alnum 
U+df is:  alnum 
U+6c34 is:  alnum 
U+1d10b is:  punct

二次

另见

iswctype

classifies a wide character according to the specified LC_CTYPE category (function)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券