char_class_type lookup_classname( ForwardIt first,
ForwardIt last,
If the character sequence [
first,
last)
represents the name of a valid character class in the currently imbued locale (that is, the string between [:
and :]
in regular expressions), returns the implementation-defined value representing this character class. Otherwise, returns zero.
If the parameter icase is true, the character class ignores character case, e.g. the regex [:lower:]
with std::regex_constants::icase generates a call to std::regex_traits<>::lookup_classname() with [
first,
last)
indicating the string "lower" and icase == true. This call returns the same bitmask as the call generated by the regex [:alpha:]
with icase == false.
The following narrow and wide character class names are always recognized by std::regex_traits<char> and std::regex_traits<wchar_t> respectively, and the classifications returned (with icase == false) correspond to the matching classifications obtained by the std::ctype facet of the imbued locale, as follows:
The classification returned for the string "w" may be exactly the same as "alnum", in which case isctype() adds '_' explicitly.
Additional classifications such as "jdigit" or "jkanji" may be provided by system-supplied locales (in which case they are also accessible through std::wctype).
[edit] Parameters 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 Type requirements -ForwardIt
must meet the requirements of LegacyForwardIterator. [edit] Return value
The bitmask representing the character classification determined by the given character class, or char_class_type() if the class is unknown.
[edit] ExampleDemonstrates 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] See also indicates membership in a character class
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