_mbsbtype
string.h:インデックス への移動
ヘッダーファイル
mbstring.h
カテゴリ
分類ルーチン
プロトタイプ
int _mbsbtype(const unsigned char *str, size_t nbyte);
説明
nbyte 引数は,文字列の先頭からのバイト数(ゼロベース)を指定します。
_mbsbtype 関数は,引数 str を検査して,nbyte で指定された場所にあるバイトがシングルバイト文字かどうか,あるいはマルチバイト文字の先行バイトまたは後続バイトかどうかを判定します。_mbsbtype 関数は,指されたバイトが無効な文字または NULL バイトかどうかを判定できます。
nbyte より前にある str 内のすべての無効なバイトは無視されます。
戻り値
_mbsbtype が返す値は,mbctype.h で定義されている次のマニフェスト定数の 1 つです。
コード例
#include <mbstring.h>
#include <mbctype.h>
int count_chars(char* input)
{
int type, i = 0, chars = 0;
while (input[i])
{
/* Obtain the type of the i-th char in the string */
type = _mbsbtype(input, i);
/* Consider single and MBCS chars as whole chars */
switch (type) {
case _MBC_LEAD:
case _MBC_SINGLE:
chars++;
break;
case _MBC_ILLEGAL:
return -1;
}
i++;
}
/* The number of chars */
return chars;
}