std::codecvt<InternT,ExternT,StateT>::max_length, do_max_length
来自 cppreference.com
在头文件 <locale> 中定义 |
||
(1) | ||
public: int max_length() const throw(); |
(直到 C++11) | |
public: int max_length() const noexcept; |
(自 C++11 起) | |
(2) | ||
protected: virtual int do_max_length() const throw(); |
(直到 C++11) | |
protected: virtual int do_max_length() const noexcept; |
(自 C++11 起) | |
1) 公共成员函数,调用最派生类的成员函数
do_max_length
。2) 返回 do_length(state, from, from_end, 1) 对于任何有效的范围
[
from,
from_end)
和任何有效的 state
可以返回的最大值。内容 |
[编辑] 返回值
由 in() 转换为一个 InternT
字符时可能消耗的 ExternT
字符的最大数量。
非转换特化 std::codecvt<char, char, std::mbstate_t> 返回 1.
[编辑] 说明
如果编码是状态相关的 (encoding() == -1),则可能消耗超过 max_length()
个外部字符来生成一个内部字符。
[编辑] 示例
运行此代码
#include <codecvt> #include <iostream> #include <locale> int main() { std::cout << "In codecvt_utf8, the longest multibyte character is " << std::codecvt_utf8<wchar_t>().max_length() << " bytes long\n"; std::cout << "In header-consuming codecvt_utf8, the longest multibyte character is " << std::codecvt_utf8<wchar_t, 0x10ffff, std::consume_header>().max_length() << " bytes long\n"; std::cout << "In this system's en_US.utf8, the longest multibyte character is " << std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>>( std::locale("en_US.utf8") ).max_length() << " bytes long\n"; std::cout << "In this system's zh_CN.gb18030, the longest multibyte character is " << std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>>( std::locale("zh_CN.gb18030") ).max_length() << " bytes long\n"; }
输出
In codecvt_utf8, the longest multibyte character is 4 bytes long In header-consuming codecvt_utf8, the longest multibyte character is 7 bytes long In this system's en_US.utf8, the longest multibyte character is 6 bytes long In this system's zh_CN.gb18030, the longest multibyte character is 4 bytes long
[编辑] 另请参阅
MB_CUR_MAX |
当前 C 区域设置中多字节字符中的最大字节数 (宏变量) |
[虚拟] |
如果恒定,则返回生成一个 InternT 字符所需的 ExternT 字符数量(虚拟保护成员函数) |