名前空間
変種
操作

mbsinit

提供: cppreference.com
< c‎ | string‎ | multibyte
ヘッダ <wchar.h> で定義
int mbsinit( const mbstate_t* ps);
(C95以上)

ps がヌルポインタでなければ、指されている mbstate_t オブジェクトが初期変換状態を表すかどうかを調べます。

目次

[編集] ノート

ゼロ初期化された 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

[編集] 参考文献

  • C11 standard (ISO/IEC 9899:2011):
  • 7.29.6.2.1 The mbsinit function (p: 441-442)
  • C99 standard (ISO/IEC 9899:1999):
  • 7.24.6.2.1 The mbsinit function (p: 387-388)

[編集] 関連項目

マルチバイト文字列を反復処理するために必要な変換状態情報
(構造体) [edit]