std::codecvt::length, std::codecvt::do_length
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <locale> 中定义
|
||
public: int length( stateT& state, |
(1) | |
protected: int do_length( stateT& state, |
(2) | |
公共成员函数,调用最派生类的成员函数
2) do_length
.原文:
public member function, calls the member function
do_length
of the most derived class.尝试转换成
externT
字符的字符数组定义的[from, from_end)
,给定的初始转换状态state
,最max
internT
字符,并返回这种转换会消耗externT
字符的数量。修改state
如果通过执行一些假想do_in(state, from, from_end, from, to, to+max, to)输出缓冲区的[to, to+max)
.原文:
attempts to convert the
externT
characters from the character array defined by [from, from_end)
, given initial conversion state state
, to at most max
internT
characters, and returns the number of externT
characters that such conversion would consume. Modifies state
as if by executing do_in(state, from, from_end, from, to, to+max, to) for some imaginary [to, to+max)
output buffer.[编辑] 返回值
externT
会被消耗掉,直到所有的do_in()
字符转换from_end-from被消耗或生产商,max
internT
字符或转换错误的字符的数量发生了.....原文:
The number of
externT
characters that would be consumed if converted by do_in()
until either all from_end-from characters were consumed or max
internT
characters were producer, or a conversion error occurred.非转换专业化std::codecvt<char, char, std::mbstate_t>回报std::min(max, from_end-from)
原文:
The non-converting specialization std::codecvt<char, char, std::mbstate_t> returns std::min(max, from_end-from)
[编辑] 示例
#include <locale> #include <string> #include <iostream> int main() { // narrow multibyte encoding std::string s = "z\u00df\u6c34\U0001d10b"; // or u8"zß水𝄋" // or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b"; std::mbstate_t mb = std::mbstate_t(); std::cout << "Only the first " << std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>>( std::locale("en_US.utf8") ).length(mb, &s[0], &s[s.size()], 2) << " bytes out of " << s.size() << " would be consumed " " to produce the first 2 characters\n"; }
输出:
Only the first 3 bytes out of 10 would be consumed to produce the first 2 characters
[编辑] 另请参阅
[虚]</div></div>
|
将字符串转换,如从文件读取时,从externT到Internt的 原文: converts a string from externT to internT, such as when reading from file (虚拟保护成员函数) |