std::mbrlen
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <cwchar> 中定义
|
||
std::size_t mbrlen( const char* s, std::size_t n, std::mbstate_t* ps); |
||
。
确定文件的大小(以字节为单位),其余的多字节字符的第一个字节指出,
s
,鉴于目前的转换状态ps
原文:
Determines the size, in bytes, of the remainder of the multibyte character whose first byte is pointed to by
s
, given the current conversion state ps
.。此函数等同类型std::mbrtowc(nullptr, s, n, ps?ps:&internal)一些隐藏的对象
internal
的号召std::mbstate_t,除了表达ps
只计算一次.原文:
This function is equivalent to the call std::mbrtowc(nullptr, s, n, ps?ps:&internal) for some hidden object
internal
of type std::mbstate_t, except that the expression ps
is evaluated only once.[编辑] 。参数。
s | - | 。元素的多字节字符串的指针。
原文: pointer to an element of a multibyte character string |
n | - | 。限制的字节数,可以检查。
原文: limit on the number of bytes in s that can be examined |
ps | - | 。指针的变量转换状态。
原文: pointer to the variable holding the conversion state |
===。 返回值。===
。 0如果下一个
n
或更少的字节完成空字符.原文:
0 if the next
n
or fewer bytes complete the null character.。完成一个有效的多字节字符的字节数(1和n)。
原文:
The number of bytes (between 1 and n) that complete a valid multibyte character
。 (size_t)-1如果出现编码错误。
。 (size_t)-2
n
如果下一个字节是可能有效的多字节字符,它仍然是不完整的后检查所有n
字节的一部分。原文:
(size_t)-2 if the next
n
bytes are part of a possibly valid multibyte character, which is still incomplete after examining all n
bytes[编辑] 。为例。
#include <clocale> #include <string> #include <iostream> #include <cwchar> int main() { // allow mbrlen() to work with UTF-8 multibyte encoding std::setlocale(LC_ALL, "en_US.utf8"); // UTF-8 narrow multibyte encoding std::string str = u8"水"; // or u8"\u6c34" or "\xe6\xb0\xb4" std::mbstate_t mb = std::mbstate_t(); int len1 = std::mbrlen(&str[0], 1, &mb); if(len1 == -2) { std::cout << "The first 1 byte of " << str << " is an incomplete multibyte char (mbrlen returns -2)\n"; } int len2 = std::mbrlen(&str[1], str.size()-1, &mb); std::cout << "The remaining " << str.size()-1 << " bytes of " << str << " hold " << len2 << " bytes of the multibyte character\n"; std::cout << "Attempting to call mbrlen() in the middle of " << str << " while in initial shift state returns " << (int)mbrlen(&str[1], str.size(), &mb) << '\n'; }
输出:
The first 1 byte of 水 is an incomplete multibyte char (mbrlen returns -2) The remaining 2 bytes of 水 hold 2 bytes of the multibyte character Attempting to call mbrlen() in the middle of 水 while in initial shift state returns -1
[编辑] 。另请参阅。
下的多字节字符转换为宽字符,给定的状态中 原文: converts the next multibyte character to wide character, given state (函数) | |
在未来的多字节字符,返回的字节数 原文: returns the number of bytes in the next multibyte character (函数) | |
[虚]</div></div>
|
计算将转换成给定的Internt的缓冲区消耗的externT字符串,该字符串的长度 原文: calculates the length of the externT string that would be consumed by conversion into given internT buffer (虚拟保护成员函数of std::codecvt )
|
C documentation for mbrlen
|