wctrans() —文字マッピングのハンドルの取得
形式
#include <wctype.h>
wctrans_t wctrans(const char *property);言語レベル
ANSI
スレッド・セーフ
はい
説明
wctrans() 関数は、wctrans_t タイプの値を戻します。 この値は、ワイド文字間のマッピングを記述しています。 ストリング引数 property はワイド文字マッピング名です。 ワイド文字マッピング名と同等の wctrans_t は、
この関数で戻されます。 このtoupperさらにtolowerワイド文字マッピング名は、すべてのロケールで定義されます。
戻り値
プロパティーが有効なワイド文字マッピング名である場合、 wctrans() 関数は、 towctrans() 関数の 2 番目の引数として有効なゼロ以外の値を戻します。 それ以外の場合は、0 を戻します。
例
この例では、英字の小文字を大文字に、英字の大文字を小文字に
変換します。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>
int main()
{
char *alpha = "abcdefghijklmnopqrstuvwxyz";
char *tocase[2] = {"toupper", "tolower"};
wchar_t *wcalpha;
int i, j;
size_t alphalen;
alphalen = strlen(alpha)+1;
wcalpha = (wchar_t *)malloc(sizeof(wchar_t)*alphalen);
mbstowcs(wcalpha, alpha, 2*alphalen);
for (i=0; i<2; ++i) {
printf("Input string: %ls\n", wcalpha);
for (j=0; j<strlen(alpha); ++j) {
wcalpha[j] = (wchar_t)towctrans((wint_t)wcalpha[j], wctrans(tocase[i]));
}
printf("Output string: %ls\n", wcalpha);
printf("\n");
}
return 0;
}
/**************** Output should be similar to: ******************
Input string: abcdefghijklmnopqrstuvwxyz
Output string: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Input string: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Output string: abcdefghijklmnopqrstuvwxyz
*******************************************************************/