mbsinit
From cppreference.net
|
定義先ヘッダ
<wchar.h>
|
||
|
int
mbsinit
(
const
mbstate_t
*
ps
)
;
|
(C95以降) | |
ps
がnullポインタでない場合、
mbsinit
関数は、指し示された
mbstate_t
オブジェクトが初期変換状態を記述しているかどうかを判定します。
目次 |
注記
ゼロ初期化された mbstate_t は常に初期変換状態を表しますが、 mbstate_t の他の値も初期変換状態を表す場合があります。
パラメータ
| ps | - | 検査対象のmbstate_tオブジェクトへのポインタ |
戻り値
0
ps
がnullポインタではなく、かつ初期変換状態を表していない場合、それ以外の場合は非ゼロ値。
例
このコードを実行
#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
参考文献
- 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関数 (p: 387-388)
関連項目
|
(C95)
|
マルチバイト文字列を反復処理するために必要な変換状態情報
(クラス) |
|
C++ documentation
for
mbsinit
|
|