mbsinit
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <wchar.h> で定義
|
||
int mbsinit( const mbstate_t* ps); |
(C95以上) | |
ps がヌルポインタでなければ、指されている mbstate_t オブジェクトが初期変換状態を表すかどうかを調べます。
ノート
ゼロ初期化された mbstate_t は必ず初期変換状態を表しますが、初期変換状態を表す他の mbstate_t の値も存在するかもしれません。
引数
| ps | - | 調べる mbstate_t オブジェクトを指すポインタ |
戻り値
ps がヌルでなく、初期変換状態を表さない場合は 0。 そうでなければ非ゼロの値。
例
Run this code
#include <locale.h>
#include <string.h>
#include <stdio.h>
#include <wchar.h>
int main(void)
{
// allow mbrlen() to work with UTF-8 multibyte encoding
setlocale(LC_ALL, "en_US.utf8");
// UTF-8 narrow multibyte encoding
const char* str = u8"水"; // or u8"\u6c34" or "\xe6\xb0\xb4"
static mbstate_t mb; // zero-initialize
(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