std::regex_traits::lookup_classname
STD::regex[医]特征:查找[医]类名
template< class ForwardIt > char_class_type lookup_classname( ForwardIt first, ForwardIt last, bool icase = false ) const; | | |
---|
如果字符序列[first, last)
表示当前注入的区域设置%28中的有效字符类的名称,即[:
和:]
在正则表达式%29中,返回表示此字符类的实现定义值。否则,返回零。
如果参数icase是true,字符类忽略字符大小写,例如正则表达式。[:lower:]带着std::regex_constants::icase生成对regex_traits<>::lookup_classname()带着[first, last)指示字符串"lower"和icase == true。此调用返回与regex生成的调用相同的位掩码。[:alpha:]带着icase == false...
在窄字符和宽字符形式中,总是可以识别以下字符类,并且分类返回%28icase == false
%29对应于std::ctype
灌输的场所的方方面面,如下所示:
character class | std::ctype classification |
---|---|
"alnum" | std::ctype_base::alnum |
"alpha" | std::ctype_base::alpha |
"blank" | std::ctype_base::blank |
"cntrl" | std::ctype_base::cntrl |
"digit" | std::ctype_base::digit |
"graph" | std::ctype_base::graph |
"lower" | std::ctype_base::lower |
"print" | std::ctype_base::print |
"punct" | std::ctype_base::punct |
"space" | std::ctype_base::space |
"upper" | std::ctype_base::upper |
"xdigit" | std::ctype_base::xdigit |
"d" | std::ctype_base::digit |
"s" | std::ctype_base::space |
"w" | std::ctype_base::alnum with '_' optionally added |
返回的字符串的分类。"w"
可能和"alnum"
,在这种情况下isctype()
加%27[医]%27
其他分类,如"jdigit"
或"jkanji"
可以由系统提供的地区%28提供,在这种情况下,它们也可以通过std::wctype
29%。
参数
first, last | - | a pair of iterators which determines the sequence of characters that represents a name of a character class |
---|---|---|
icase | - | if true, ignores the upper/lower case distinction in the character classification |
类型要求
---。
返回值
表示由给定字符类确定的字符分类的位掩码,或char_class_type()
如果这个类是未知的。
例
证明是一种定制的正则表达式[医]查找的特征实现[医]类名/类型化
二次
#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 "ナウシカ"
}
二次
产出:
二次
alnums: 風の谷のナウシカ
katakana: ナウシカ
二次
另见
isctype | indicates membership in a character class (public member function) |
---|---|
wctype | looks up a character classification category in the current C locale (function) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。