std::regex_traits<CharT>::isctype (3) - Linux Man Pages
std::regex_traits<CharT>::isctype: std::regex_traits<CharT>::isctype
Command to display std::regex_traits<CharT>::isctype
manual in Linux: $ man 3 std::regex_traits<CharT>::isctype
NAME
std::regex_traits<CharT>::isctype - std::regex_traits<CharT>::isctype
Synopsis
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:
1) First converts f to some temporary value m of type std::ctype_base::mask in implementation-defined manner
2) Then attempts to classify the character in the imbued locale by calling std::use_facet<std::ctype<CharT>>(getloc()).is(m, c). If that returned true, true is returned by isctype().
3) Otherwise, checks whether c equals '_' and the bitmask f includes the result of calling lookup_classname() for the character class [:w:], in which case true is returned.
4) Otherwise, false is returned.
Parameters
c - the character to classify
f - the bitmask obtained from one or several calls to lookup_classname()
Return value
true if c is classified by f, false otherwise.
Notes
The description above summarizes C++14; the C++11 phrasing required this function to return true for '_' in all cases (LWG_issue_2018)
Example
// Run this code
#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';
}
Output:
true true
true false
false false
demonstraits a custom regex_traits implementation of lookup_classname/isctype
// Run this code
#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 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: ナウシカ
See also
gets a character class by name
lookup_classname (public member function)
do_is classifies a character or a character sequence
(virtual protected member function of std::ctype<CharT>)
[virtual]
classifies a wide character according to the specified LC_CTYPE category
iswctype (function)
Pages related to std::regex_traits<CharT>::isctype
- std::regex_traits<CharT>::imbue (3) - std::regex_traits<CharT>::imbue
- std::regex_traits<CharT>::getloc (3) - std::regex_traits<CharT>::getloc
- std::regex_traits<CharT>::length (3) - std::regex_traits<CharT>::length
- std::regex_traits<CharT>::lookup_classname (3) - std::regex_traits<CharT>::lookup_classname
- std::regex_traits<CharT>::lookup_collatename (3) - std::regex_traits<CharT>::lookup_collatename
- std::regex_traits<CharT>::regex_traits (3) - std::regex_traits<CharT>::regex_traits
- std::regex_traits<CharT>::transform (3) - std::regex_traits<CharT>::transform
- std::regex_traits<CharT>::transform_primary (3) - std::regex_traits<CharT>::transform_primary
- std::regex_traits<CharT>::translate (3) - std::regex_traits<CharT>::translate
- std::regex_traits<CharT>::translate_nocase (3) - std::regex_traits<CharT>::translate_nocase
- std::regex_traits<CharT>::value (3) - std::regex_traits<CharT>::value
- std::regex_traits (3) - std::regex_traits
- std::regex_token_iterator (3) - std::regex_token_iterator
- std::regex_token_iterator<BidirIt,CharT,Traits>::operator*,operator-> (3) - std::regex_token_iterator<BidirIt,CharT,Traits>::operator*,operator->
- std::regex_token_iterator<BidirIt,CharT,Traits>::operator++,operator++(int) (3) - std::regex_token_iterator<BidirIt,CharT,Traits>::operator++,operator++(int)
- std::regex_token_iterator<BidirIt,CharT,Traits>::operator= (3) - std::regex_token_iterator<BidirIt,CharT,Traits>::operator=