wctob
From cppreference.com
| ヘッダー <wchar.h> で定義 |
||
| int wctob( wint_t c ); |
(C95 以降) | |
ワイド文字cを、初期シフト状態におけるマルチバイト文字表現が1バイトである場合に、1バイトに狭めます。
これは通常、ASCII文字セットからの文字で可能です。なぜなら、ほとんどのマルチバイトエンコーディング(UTF-8など)では、これらの文字をエンコードするために1バイトを使用するからです。
目次 |
[編集] パラメータ
| c | - | 狭めるワイド文字 |
[編集] 戻り値
cが初期シフト状態において長さ1のマルチバイト文字を表さない場合、EOF。
それ以外の場合は、cの1バイト表現をunsigned charとして取得し、intに変換したもの。
[編集] 例
このコードを実行
#include <locale.h> #include <wchar.h> #include <stdio.h> #include <assert.h> void try_narrowing(wchar_t c) { int cn = wctob(c); if(cn != EOF) printf("%#x narrowed to %#x\n", c, cn); else printf("%#x could not be narrowed\n", c); } int main(void) { char* utf_locale_present = setlocale(LC_ALL, "th_TH.utf8"); assert(utf_locale_present); puts("In Thai UTF-8 locale:"); try_narrowing(L'a'); try_narrowing(L'๛'); char* tis_locale_present = setlocale(LC_ALL, "th_TH.tis620"); assert(tis_locale_present); puts("In Thai TIS-620 locale:"); try_narrowing(L'a'); try_narrowing(L'๛'); }
実行結果の例
In Thai UTF-8 locale: 0x61 narrowed to 0x61 0xe5b could not be narrowed In Thai TIS-620 locale: 0x61 narrowed to 0x61 0xe5b narrowed to 0xfb
[編集] 参照
- C11標準 (ISO/IEC 9899:2011)
- 7.29.6.1.2 The wctob function (p: 441)
- C99標準 (ISO/IEC 9899:1999)
- 7.24.6.1.2 The wctob function (p: 387)
[編集] 関連項目
| (C95) |
可能であれば、1バイトのナロー文字をワイド文字にワイド化する (関数) |
| C++ ドキュメント (
wctob) | |