Namespaces
Variants

std::regex_traits<CharT>:: isctype

From cppreference.net
Regular expressions library
Classes
(C++11)
Algorithms
Iterators
Exceptions
Traits
Constants
(C++11)
Regex Grammar
bool isctype ( CharT c, char_class_type f ) const ;

문자 c f 로 식별되는 문자 클래스에 속하는지 여부를 결정합니다. 여기서 f lookup_classname() 이 반환한 값이거나 여러 such 값들의 비트 OR 연산 결과입니다.

표준 라이브러리의 std::regex_traits 특수화에서 제공되는 이 함수의 버전은 다음을 수행합니다:

1) 먼저 f m 타입의 값으로 변환합니다. 이때 std::ctype_base::mask 를 사용합니다.
페이지 lookup_classname() 의 표에 나열된 각 std::ctype 카테고리에 대해, 해당 카테고리에 해당하는 f 의 비트들이 설정되어 있으면, m 에서도 해당 비트들이 설정될 것입니다.
2) 그런 다음 임뷰드 로케일에서 문자를 분류하기 위해 다음을 호출합니다: std:: use_facet < std:: ctype < CharT >> ( getloc ( ) ) . is ( m, c ) .
  • 만약 이것이 true 를 반환하면, isctype() 또한 true 를 반환합니다.
  • 그렇지 않고, c '_' 이고, f 가 문자 클래스 [:w:] 에 대해 lookup_classname() 호출 결과를 포함하는 경우 true 가 반환되며, 그렇지 않으면 false 가 반환됩니다.

목차

매개변수

c - 분류할 문자
f - lookup_classname() 을 한 번 또는 여러 번 호출하여 얻은 비트마스크

반환값

true 만약 c f 에 의해 분류될 경우, false 그 외의 경우.

예제

#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:]는 [:alnum:]에 '_'를 더한 것입니다
    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';
}

출력:

true true
true false
false false

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 "ナウシカ"
}

출력:

alnums: 風の谷のナウシカ
katakana: ナウシカ

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 2018 C++11 m 값이 명시되지 않음 lookup_classname() 의 최소 지원과 일치

참고 항목

이름으로 문자 클래스를 가져옴
(public member function)
[virtual]
문자 또는 문자 시퀀스를 분류함
( std::ctype<CharT> 의 virtual protected member function)
지정된 LC_CTYPE 카테고리에 따라 와이드 문자를 분류함
(function)