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

std::regex_traits::isctype

bool isctype( CharT c, char_class_type f ) const;

?

?

确定字符是否c属于由f返回的值。lookup_classname()或按位或数个这样的值。

的标准库专门化中提供的此函数的版本。std::regex_traits是否有下列情况:

1%29新皈依者f到某个临时值m类型std::ctype_base::mask在执行方面---确定的方式

2%29然后尝试通过调用std::use_facet<std::ctype<CharT>>(getloc()).is(m, c).如果它回来了true,,,trueisctype()...

3%29否则,检查是否c等号'_'和比特掩码f包括调用的结果。lookup_classname()用于字符类[:w:],在这种情况下true会被归还。

4%29否则,false会被归还。

参数

c

-

the character to classify

f

-

the bitmask obtained from one or several calls to lookup_classname()

返回值

true如果cf,,,false否则。

注记

上面的描述总结了C++14;C++11的措辞要求此函数返回true for'_'在所有情况下%28lwg第2018期29%。

二次

代码语言:javascript
复制
#include <iostream>
#include <string>
#include <regex>
 
int main()
{
    std::regex_traits<char> t;
    std::string str_alnum = "alnum";
    auto a = t.lookup_classname(str_alnum.begin(), str_alnum.end());
    std::string str_w = "w"; // [:w:] is [:alnum:] plus '_'
    auto w = t.lookup_classname(str_w.begin(), str_w.end());
    std::cout << std::boolalpha
              << t.isctype('A', w) << ' ' << t.isctype('A', a) << '\n'
              << t.isctype('_', w) << ' ' << t.isctype('_', a) << '\n'
              << t.isctype(' ', w) << ' ' << t.isctype(' ', a) << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
true true
true false
false false

二次

证明是一种定制的正则表达式[医]查找的特征实现[医]类名/类型化

二次

代码语言:javascript
复制
#include <iostream>
#include <locale>
#include <regex>
#include <cwctype>
 
// This custom regex traits uses wctype/iswctype to implement lookup_classname/isctype
struct wctype_traits : std::regex_traits<wchar_t>
{
    using char_class_type = std::wctype_t;
    template<class It>
    char_class_type lookup_classname(It first, It last, bool=false) const {
        return std::wctype(std::string(first, last).c_str());
    }
    bool isctype(wchar_t c, char_class_type f) const {
        return std::iswctype(c, f);
    }
};
 
int main()
{
    std::locale::global(std::locale("ja_JP.utf8"));
    std::wcout.sync_with_stdio(false);
    std::wcout.imbue(std::locale());
 
    std::wsmatch m;
    std::wstring in = L"風の谷のナウシカ";
    // matches all characters (they are classified as alnum)
    std::regex_search(in, m, std::wregex(L"([[:alnum:]]+)"));
    std::wcout << "alnums: " << m[1] << '\n'; // prints "風の谷のナウシカ"
    // matches only the kanji
    std::regex_search(in, m,
                      std::basic_regex<wchar_t, wctype_traits>(L"([[:jkata:]]+)"));
    std::wcout << "katakana: " << m[1] << '\n'; // prints "ナウシカ"
}

二次

产出:

二次

代码语言:javascript
复制
alnums: 風の谷のナウシカ
katakana: ナウシカ

二次

另见

lookup_classname

gets a character class by name (public member function)

do_is virtual

classifies a character or a character sequence (virtual protected member function of std::ctype)

iswctype

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

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com