Namespaces
Variants

std:: isxdigit (std::locale)

From cppreference.net
헤더 파일에 정의됨 <locale>
template < class CharT >
bool isxdigit ( CharT ch, const locale & loc ) ;

주어진 문자가 주어진 로캘의 std::ctype 패싯에 의해 16진수 숫자로 분류되는지 확인합니다.

목차

매개변수

ch - 문자
loc - 로케일

반환값

해당 문자가 16진수 숫자로 분류되면 true 를 반환하고, 그렇지 않으면 false 를 반환합니다.

가능한 구현

template<class CharT>
bool isxdigit(CharT ch, const std::locale& loc)
{
    return std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::xdigit, ch);
}

예제

#include <iostream>
#include <locale>
#include <string>
#include <unordered_set>
struct gxdigit_ctype : std::ctype<wchar_t>
{
    std::unordered_set<wchar_t> greek_digits{L'α', L'β', L'γ', L'δ', L'ε', L'ζ'};
    bool do_is(mask m, char_type c) const override
    {
        return (m & xdigit) && greek_digits.contains(c)
            ? true // 처음 6개의 그리스어 소문자가 숫자로 분류됨
            : ctype::do_is(m, c); // 나머지는 부모 클래스에 위임
    }
};
int main()
{
    std::wstring text = L"0123456789abcdefABCDEFαβγδεζηθικλμ";
    std::locale loc(std::locale(""), new gxdigit_ctype);
    std::locale::global(std::locale("en_US.utf8"));
    std::wcout.imbue(std::locale());
    std::wcout << "텍스트 내 16진수 숫자: ";
    for (const wchar_t c : text)
        if (std::isxdigit(c, loc))
            std::wcout << c << L' ';
    std::wcout << L'\n';
    std::wcout << "텍스트 내 16진수 숫자가 아닌 문자: ";
    for (const wchar_t c : text)
        if (not std::isxdigit(c, loc))
            std::wcout << c << L' ';
    std::wcout << L'\n';
}

출력:

Hexadecimal digits in text: 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F α β γ δ ε ζ
Not hexadecimal digits in text: η θ ι κ λ μ

참고 항목

문자가 16진수 문자인지 확인합니다
(함수)
와이드 문자가 16진수 문자인지 확인합니다
(함수)