mbsinit
From cppreference.com
| ヘッダー <wchar.h> で定義 |
||
| int mbsinit( const mbstate_t* ps); |
(C95 以降) | |
psがヌルポインタでない場合、mbsinit関数は、指されているmbstate_tオブジェクトが初期変換状態を表しているかどうかを判断します。
目次 |
[編集] 注記
ゼロ初期化されたmbstate_tは常に初期変換状態を表しますが、初期変換状態を表す他の値も存在する可能性があります。
[編集] パラメータ
| ps | - | 検査するmbstate_tオブジェクトへのポインタ |
[編集] 戻り値
psがヌルポインタでなく、初期変換状態を表さない場合は0、それ以外の場合はゼロ以外の値。
[編集] 例
このコードを実行
#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++ ドキュメント for mbsinit
| |