Namespaces
Variants

std::regex_traits<CharT>:: lookup_classname

From cppreference.net
Regular expressions library
Classes
(C++11)
Algorithms
Iterators
Exceptions
Traits
Constants
(C++11)
Regex Grammar
template < class ForwardIt >

char_class_type lookup_classname ( ForwardIt first,
ForwardIt last,

bool icase = false ) const ;

문자 시퀀스 [ first , last ) 가 현재 임뷰드된 로캘에서 유효한 문자 클래스의 이름을 나타내는 경우(즉, 정규 표현식에서 [: :] 사이의 문자열), 이 문자 클래스를 나타내는 구현 정의 값을 반환합니다. 그렇지 않으면 0을 반환합니다.

매개변수 icase true 인 경우, 문자 클래스는 대소문자를 구분하지 않습니다. 예를 들어 정규식 [:lower:] std::regex_constants::icase 를 사용하면 std:: regex_traits <> :: lookup_classname ( ) 호출이 생성되며, 이때 [ first , last ) 는 문자열 "lower" 를 가리키고 icase == true 입니다. 이 호출은 정규식 [:alpha:] icase == false 를 사용하여 생성된 호출과 동일한 비트마스크를 반환합니다.

다음의 좁은 문자 및 넓은 문자 클래스 이름들은 항상 std:: regex_traits < char > std:: regex_traits < wchar_t > 에 의해 각각 인식되며, 반환되는 분류( icase == false 인 경우)는 다음과 같이 임뷰드(imbued)된 로캘의 std::ctype 패싯을 통해 얻은 일치하는 분류에 대응합니다:

문자 클래스 이름 std::ctype 분류
좁은 문자 넓은 문자
"alnum" L "alnum" std::ctype_base::alnum
"alpha" L "alpha" std::ctype_base::alpha
"blank" L "blank" std::ctype_base::blank
"cntrl" L "cntrl" std::ctype_base::cntrl
"digit" L "digit" std::ctype_base::digit
"graph" L "graph" std::ctype_base::graph
"lower" L "lower" std::ctype_base::lower
"print" L "print" std::ctype_base::print
"punct" L "punct" std::ctype_base::punct
"space" L "space" std::ctype_base::space
"upper" L "upper" std::ctype_base::upper
"xdigit" L "xdigit" std::ctype_base::xdigit
"d" L "d" std::ctype_base::digit
"s" L "s" std::ctype_base::space
"w" L "w" std::ctype_base::alnum
'_' 가 선택적으로 추가됨

문자열에 대해 반환된 분류가 "w" "alnum" 와 정확히 동일할 수 있으며, 이 경우 isctype() 은 명시적으로 '_' 를 추가합니다.

추가 분류로서 "jdigit" 또는 "jkanji" 같은 분류가 시스템 제공 로캘에 의해 제공될 수 있습니다 (이 경우에는 std::wctype 를 통해서도 접근 가능합니다).

목차

매개변수

first, last - 문자 클래스 이름을 나타내는 문자 시퀀스를 결정하는 한 쌍의 반복자
icase - true 인 경우 문자 분류에서 대소문자 구분을 무시함
타입 요구사항
-
ForwardIt LegacyForwardIterator 요구사항을 충족해야 함

반환값

주어진 문자 클래스에 의해 결정된 문자 분류를 나타내는 비트마스크, 또는 char_class_type ( ) 클래스를 알 수 없는 경우.

예제

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

참고 항목

문자 클래스 멤버십을 나타냄
(public member function)
현재 C 로캘에서 문자 분류 카테고리를 조회함
(function)