mbsinit
From cppreference.net
|
定义于头文件
<wchar.h>
|
||
|
int
mbsinit
(
const
mbstate_t
*
ps
)
;
|
(C95 起) | |
如果
ps
不是空指针,
mbsinit
函数将判断所指向的
mbstate_t
对象是否描述初始转换状态。
目录 |
注释
尽管零初始化的 mbstate_t 始终表示初始转换状态,但可能存在其他 mbstate_t 值同样表示初始转换状态。
参数
| ps | - | 指向要检查的 mbstate_t 对象的指针 |
返回值
0
如果
ps
不是空指针且不表示初始转换状态,否则返回非零值。
示例
运行此代码
#include <locale.h> #include <string.h> #include <stdio.h> #include <wchar.h> int main(void) { // 允许 mbrlen() 使用 UTF-8 多字节编码 setlocale(LC_ALL, "en_US.utf8"); // UTF-8 窄多字节编码 const char* str = u8"水"; // 或 u8"\u6c34" 或 "\xe6\xb0\xb4" static mbstate_t mb; // 零初始化 (void)mbrlen(&str[0], 1, &mb); if (!mbsinit(&mb)) { printf("After processing the first 1 byte of %s,\n" "the conversion state is not initial\n\n", str); } (void)mbrlen(&str[1], strlen(str), &mb); if (mbsinit(&mb)) { printf("After processing the remaining 2 bytes of %s,\n" "the conversion state is initial conversion state\n", str); } }
输出:
After processing the first 1 byte of 水, the conversion state is not initial After processing the remaining 2 bytes of 水, the conversion state is initial conversion state
参考文献
- C17 标准 (ISO/IEC 9899:2018):
-
- 7.29.6.2.1 mbsinit 函数 (p: 322)
- C11 标准 (ISO/IEC 9899:2011):
-
- 7.29.6.2.1 mbsinit 函数 (p: 441-442)
- C99标准(ISO/IEC 9899:1999):
-
- 7.24.6.2.1 mbsinit函数(页码:387-388)
参见
|
(C95)
|
用于迭代多字节字符串所需的转换状态信息
(类) |
|
C++ 文档
关于
mbsinit
|
|