| Localization library | |||||||||||||||||||||||||
| Regular expressions library(C++11) | |||||||||||||||||||||||||
| Formatting library(C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Classes | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
| Algorithms | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
| Iterators | ||||
(C++11) | ||||
(C++11) | ||||
| Exceptions | ||||
(C++11) | ||||
| Traits | ||||
(C++11) | ||||
| Constants | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
| Regex Grammar | ||||
(C++11) |
| Member functions | ||||
regex_traits::isctype | ||||
bool isctype( CharT c, char_class_type f)const; | ||
Determines whether the characterc belongs to the character class identified byf, which, in turn, is a value returned bylookup_classname() or a bitwise OR of several such values.
The version of this function provided in the standard library specializations ofstd::regex_traits does the following:
isctype() will also returntrue.[:w:],true is returned, otherwisefalse is returned.Contents |
| c | - | the character to classify |
| f | - | the bitmask obtained from one or several calls tolookup_classname() |
true ifc is classified byf,false otherwise.
#include <iostream>#include <regex>#include <string> 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';}
Output:
true truetrue falsefalse false
Demonstrates a custom regex traits implementation oflookup_classname() /isctype():
#include <cwctype>#include <iostream>#include <locale>#include <regex> // 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{returnstd::wctype(std::string(first, last).c_str());} bool isctype(wchar_t c, char_class_type f)const{returnstd::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 katakanastd::regex_search(in, m,std::basic_regex<wchar_t, wctype_traits>(L"([[:jkata:]]+)"));std::wcout<<"katakana: "<< m[1]<<'\n';// prints "ナウシカ"}
Output:
alnums: 風の谷のナウシカkatakana: ナウシカ
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 2018 | C++11 | the value ofm was unspecified | matcheslookup_classname()'s minimal support |
| gets a character class by name (public member function)[edit] | |
[virtual] | classifies a character or a character sequence (virtual protected member function of std::ctype<CharT>)[edit] |
classifies a wide character according to the specifiedLC_CTYPE category(function)[edit] |