bool isctype( CharT c, char_class_type f ) const;
Determines whether the character c belongs to the character class identified by f, which, in turn, is a value returned by lookup_classname() or a bitwise OR of several such values.
The version of this function provided in the standard library specializations of std::regex_traits does the following:
For each
std::ctypecategory listed in the table in the page
lookup_classname(), if the bits in
fcorresponding to the category are set, the corresponding bits in
mwill also be set.
2)Then attempts to classify the character in the imbued locale by calling
std::use_facet<std::ctype<CharT>>(getloc()).is(m, c).
isctype()
will also return true.[:w:]
, true is returned, otherwise false is returned.true if c is classified by f, false otherwise.
[edit] Example#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 true true false false false
Demonstrates a custom regex traits implementation of lookup_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 { 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 katakana std::regex_search(in, m, std::basic_regex<wchar_t, wctype_traits>(L"([[:jkata:]]+)")); std::wcout << "katakana: " << m[1] << '\n'; // prints "ãã¦ã·ã«" }
Output:
alnums: 風ã®è°·ã®ãã¦ã·ã« katakana: ãã¦ã·ã«[edit] Defect reports
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 of m was unspecified matches lookup_classname()'s minimal support [edit] See also gets a character class by namestd::ctype<CharT>
) [edit] classifies a wide character according to the specified LC_CTYPE
category
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4