std::isxdigit(std::locale)
来自cppreference.com
| 在标头 <locale> 定义
|
||
| |
||
检查给定字符按给定本地环境的 std::ctype 刻面是否分类为十六进制数位。
参数
| ch | - | 字符 |
| loc | - | 本地环境 |
返回值
若字符被分类为十六进制数位则返回 true,否则返回 false。
可能的实现
|
示例
运行此代码
#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 << "文本中的十六进制数字: ";
for (const wchar_t c : text)
if (std::isxdigit(c, loc))
std::wcout << c << L' ';
std::wcout << L'\n';
std::wcout << "文本中的非十六进制数字字符: ";
for (const wchar_t c : text)
if (not std::isxdigit(c, loc))
std::wcout << c << L' ';
std::wcout << L'\n';
}
输出:
文本中的十六进制数字: 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F α β γ δ ε ζ
文本中的非十六进制数字字符: η θ ι κ λ μ
参阅
| 检查字符是为十六进制字符 (函数) | |
| 检查宽字符是否为十六进制字符 (函数) |