std::codecvt::in, std::codecvt::do_in
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <locale> 中定义
|
||
public: result in( stateT& state, |
(1) | |
protected: result do_in( stateT& state, |
(2) | |
公共成员函数,调用最派生类的成员函数
2) do_in
.原文:
public member function, calls the member function
do_in
of the most derived class.如果此
codecvt
刻面定义了一个转换,外部字符翻译,从源范围[from, from_end)
内部的字符,将其结果,在其后的位置处开始to
。转换不超过from_end - from外部字符和写入不超过to_end - to内部字符。叶from_next
to_next
指着一个超越的最后一个元素,成功地转换.原文:
If this
codecvt
facet defines a conversion, translates the external characters from the source range [from, from_end)
to internal characters, placing the results in the subsequent locations starting at to
. Converts no more than from_end - from external characters and writes no more than to_end - to internal characters. Leaves from_next
and to_next
pointing one beyond the last element successfully converted.这
codecvt
方面如果不定义转换,没有字符被转换。 to_next
被设置为等于to
,state
是不变的,和std::codecvt_base::noconv返回.原文:
If this
codecvt
facet does not define a conversion, no characters are converted. to_next
is set to be equal to to
, state
is unchanged, and std::codecvt_base::noconv is returned.目录 |
[编辑] 返回值
值类型std::codecvt_base::result,表示成功的状态如下:
原文:
A value of type std::codecvt_base::result, indicating the success status as follows:
ok
|
转换完成
|
partial
|
没有足够的空间在输出缓冲区中的或意外的源缓冲器结束
原文: not enough space in the output buffer or unexpected end of source buffer |
error
|
遇到不能转换的字符
原文: encountered a character that could not be converted |
noconv
|
此方面,非转换,没有输出写入
原文: this facet is non-converting, no output written |
非转换专业化std::codecvt<char, char, std::mbstate_t>总是返回std::codecvt_base::noconv
原文:
The non-converting specialization std::codecvt<char, char, std::mbstate_t> always returns std::codecvt_base::noconv
[编辑] 注释
需要该from <= from_end && to <= to_end,
state
代表初始移位状态,或通过以下方式获得序列中的前面的字符转换.原文:
Requires that from <= from_end && to <= to_end and that
state
either representing the initial shift state or obtained by converting the preceding characters in the sequence.影响
state
是故意未指定。在标准方面,它是用来保持移动状态时的调用std::mbsrtowcs,因此,更新,以反映后,最后处理的外部字符转换状态,但用户定义的方面是自由地使用它,以维持任何其他国家,例如:遇到特殊字符数数.原文:
The effect on
state
is deliberately unspecified. In standard facets, it is used to maintain shift state like when calling std::mbsrtowcs, and is therefore updated to reflect the conversion state after the last processed external character, but a user-defined facet is free to use it to maintain any other state, e.g. count the number of special characters encountered.[编辑] 示例
#include <iostream> #include <string> #include <locale> int main() { std::locale::global(std::locale("en_US.utf8")); auto& f = std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>>(std::locale()); std::string external = u8"z\u00df\u6c34\U0001d10b"; // or u8"zß水𝄋" // or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b"; // note that the following can be done with wstring_convert std::mbstate_t mb = std::mbstate_t(); // initial shift state std::wstring internal(external.size(), '\0'); const char* from_next; wchar_t* to_next; f.in(mb, &external[0], &external[external.size()], from_next, &internal[0], &internal[internal.size()], to_next); // error checking skipped for brevity internal.resize(to_next - &internal[0]); std::wcout << L"The string in wide encoding: " << internal << '\n'; }
输出:
The string in wide encoding: zß水𝄋
[编辑] 另请参阅
[虚]</div></div>
|
读取相关的文件 (虚拟保护成员函数of std::basic_filebuf )
|
一个字节的字符串转换成宽字符串 原文: converts a byte string into a wide string (公共成员函数of std::wstring_convert )
| |
将一个狭窄的多字节字符的字符串,宽字符串,给定的状态 原文: converts a narrow multibyte character string to wide string, given state (函数) | |
[虚]</div></div>
|
转换成一个字符串,如写入文件时,从Internt的externT 原文: converts a string from internT to externT, such as when writing to file (虚拟保护成员函数) |