std::ctype_byname
来自 cppreference.cn
定义于头文件 <locale> |
||
template< class CharT > class ctype_byname : public std::ctype<CharT>; |
||
std::ctype_byname
是一个 std::ctype facet,它封装了在其构造时指定的区域设置的字符分类规则。
目录 |
[编辑] 特化
标准库保证提供以下特化
定义于头文件
<locale> | |
std::ctype_byname<char> | 提供窄字符分类(使用表查找进行字符分类) |
std::ctype_byname<wchar_t> | 提供宽字符分类 |
[编辑] 嵌套类型
类型 | 定义 |
mask
|
typename std::ctype<CharT>::mask |
[编辑] 成员函数
(构造函数) |
构造一个新的 ctype_byname facet(public member function) |
(析构函数) |
销毁一个 ctype_byname facet(protected member function) |
std::ctype_byname::ctype_byname
explicit ctype_byname( const char* name, std::size_t refs = 0 ); |
||
explicit ctype_byname( const std::string& name, std::size_t refs = 0 ); |
(自 C++11 起) | |
为具有 name 的区域设置构造一个新的 std::ctype_byname
facet。
refs 用于资源管理:如果 refs == 0,则当持有它的最后一个 std::locale 对象被销毁时,实现会销毁该 facet。 否则,该对象不会被销毁。
参数
name | - | 区域设置的名称 |
refs | - | 链接到 facet 的引用数 |
std::ctype_byname::~ctype_byname
protected: ~ctype_byname(); |
||
销毁 facet。
继承自 std::ctype<CharT> (仅当 CharT
不是 char 时)
嵌套类型
类型 | 定义 |
char_type
|
CharT
|
数据成员
成员 | 描述 |
std::locale::id id [static] |
facet 的标识符 |
成员函数
调用 do_is (public member function of std::ctype<CharT> ) | |
调用 do_scan_is (public member function of std::ctype<CharT> ) | |
调用 do_scan_not (public member function of std::ctype<CharT> ) | |
toupper (public member function of std::ctype<CharT> ) | |
tolower (public member function of std::ctype<CharT> ) | |
调用 do_widen (public member function of std::ctype<CharT> ) | |
调用 do_narrow (public member function of std::ctype<CharT> ) |
受保护的成员函数
[virtual] |
将一个或多个字符转换为大写 (virtual protected member function of std::ctype<CharT> ) |
[virtual] |
将一个或多个字符转换为小写 (virtual protected member function of std::ctype<CharT> ) |
[virtual] |
将一个或多个字符从 char 转换为 CharT (virtual protected member function of std::ctype<CharT> ) |
[virtual] |
将一个或多个字符从 CharT 转换为 char(virtual protected member function of std::ctype<CharT> ) |
[virtual] |
分类一个字符或字符序列 (virtual protected member function of std::ctype<CharT> ) |
[virtual] |
在序列中定位第一个符合给定分类的字符 (virtual protected member function of std::ctype<CharT> ) |
[virtual] |
在序列中定位第一个不符合给定分类的字符 (virtual protected member function of std::ctype<CharT> ) |
继承自 std::ctype<char> (仅当 CharT
是 char 时)
嵌套类型
类型 | 定义 |
char_type
|
char |
数据成员
成员 | 描述 |
std::locale::id id [static] |
facet 的标识符 |
const std::size_t table_size [static] |
分类表的大小,至少为 256 |
成员函数
获取字符分类表 (public member function of std::ctype<char> ) | |
[static] |
获取 “C” 区域设置字符分类表 (public static member function of std::ctype<char> ) |
is (public member function of std::ctype<char> ) | |
scan_is (public member function of std::ctype<char> ) | |
scan_not (public member function of std::ctype<char> ) | |
toupper (public member function of std::ctype<CharT> ) | |
tolower (public member function of std::ctype<CharT> ) | |
调用 do_widen (public member function of std::ctype<CharT> ) | |
调用 do_narrow (public member function of std::ctype<CharT> ) |
受保护的成员函数
[virtual] |
将一个或多个字符转换为大写 (virtual protected member function of std::ctype<CharT> ) |
[virtual] |
将一个或多个字符转换为小写 (virtual protected member function of std::ctype<CharT> ) |
[virtual] |
将一个或多个字符从 char 转换为 CharT (virtual protected member function of std::ctype<CharT> ) |
[virtual] |
将一个或多个字符从 CharT 转换为 char(virtual protected member function of std::ctype<CharT> ) |
继承自 std::ctype_base
嵌套类型
类型 | 定义 |
mask
|
未指明的 BitmaskType 类型(枚举,整数类型或 bitset) |
成员常量
space [static] |
mask 的值,用于标识空白字符分类(public static member constant) |
print [static] |
mask 的值,用于标识可打印字符分类(public static member constant) |
cntrl [static] |
mask 的值,用于标识控制字符分类(public static member constant) |
upper [static] |
mask 的值,用于标识大写字符分类(public static member constant) |
lower [static] |
mask 的值,用于标识小写字符分类(public static member constant) |
alpha [static] |
mask 的值,用于标识字母字符分类(public static member constant) |
digit [static] |
mask 的值,用于标识数字字符分类(public static member constant) |
punct [static] |
mask 的值,用于标识标点字符分类(public static member constant) |
xdigit [static] |
mask 的值,用于标识十六进制数字字符分类(public static member constant) |
blank [static] (C++11) |
mask 的值,用于标识空白字符分类(public static member constant) |
alnum [static] |
alpha | digit (public static member constant) |
graph [static] |
alnum | punct (public static member constant) |
[编辑] 注解
std::ctype_byname<char> 在 <locale> 的概要中被错误地声明为显式特化,并且该声明已通过 LWG issue 1298 的决议移除,但它仍然是一个必需的特化,就像 std::ctype_byname<wchar_t> 一样。
[编辑] 示例
运行此代码
#include <iostream> #include <locale> int main() { wchar_t c = L'\u00de'; // capital letter thorn std::locale loc("C"); std::cout << "isupper('Þ', C locale) returned " << std::boolalpha << std::isupper(c, loc) << '\n'; loc = std::locale(loc, new std::ctype_byname<wchar_t>("en_US.utf8")); std::cout << "isupper('Þ', C locale with Unicode ctype) returned " << std::boolalpha << std::isupper(c, loc) << '\n'; }
输出
isupper('Þ', C locale) returned false isupper('Þ', C locale with Unicode ctype) returned true
[编辑] 缺陷报告
以下行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。
DR | 应用于 | 已发布行为 | 正确行为 |
---|---|---|---|
LWG 16 | C++98 | 显式特化 std::ctype_byname<char> 的定义 错误指定了 do_narrow 的名称和参数列表 |
已更正 |
LWG 616 | C++98 | 在 mask 的定义中缺少 typename 消歧义符 |
已添加 |
[编辑] 参见
ctype (class template) | |
std::ctype 对类型 char 的特化 (class template specialization) |