_mbbtype
string.h:インデックス への移動
ヘッダー ファイル
mbstring.h
カテゴリ
分類ルーチン
プロトタイプ
int _mbbtype(unsigned char ch, int mode);
説明
_mbbtype 関数はマルチバイト引数である文字 ch を調べて、それがシングルバイト文字なのか、それともマルチバイト文字の先行バイトまたは後続バイトなのかを判定します。 _mbbtype 関数は ch が無効な文字かどうかを判定できます。
戻り値
戻り値は、ch の値と、ch に対して行う検査によって異なります。
_mbbtype の戻り値は、mbctype.h に定義されている以下のマニフェスト定数のいずれかになります。
| mode の値 | ch の値 | 行う検査 | 戻り値 |
|---|---|---|---|
mode != 1 |
シングルバイト |
有効なシングルバイトか先行バイトか |
_MBC_SINGLE |
mode != 1 |
マルチバイト文字の先行バイト |
有効なシングルバイトか先行バイトか |
_MBC_LEAD |
mode = 1 |
マルチバイト文字の後続バイト |
有効なシングルバイトか後続バイトか |
_MBC_TRAIL |
|
任意の値 |
任意の値 |
有効な文字 |
_MBC_ILLEGAL |
例
#include <mbstring.h>
#include <mbctype.h>
int count_chars(char* input)
{
int last_type = 0;
int chars = 0;
while (*input)
{
/* Obtain the type of the current char based on the type of the last one */
last_type = _mbbtype(*input, last_type);
/* Consider single and MBCS chars as whole chars. For illegal chars exit with -1 */
switch (last_type)
{
case _MBC_LEAD:
case _MBC_SINGLE:
chars++;
break;
case _MBC_ILLEGAL:
return -1;
}
input++;
}
/* The number of chars calculated */
return chars;
}