towctrans() — ワイド文字の変換

形式

#include <wctype.h>
wint_t towctrans(wint_t wc, wctrans_t desc);

言語レベル

ANSI

スレッド・セーフ

はい

ロケール依存

コンパイル・コマンドで LOCALETYPE(*LOCALE) が指定される場合、この関数の振る舞いは、現行ロケールの LC_CTYPE カテゴリーの影響を受ける可能性があります。 また、コンパイル・コマンドで LOCALETYPE(*LOCALEUCS2) または LOCALETYPE(*LOCALEUTF) オプションのいずれかが指定される場合、 現行ロケールの LC_UNI_CTYPE カテゴリーの影響も受ける可能性があります。 この関数は、コンパイル・コマンドに対して LOCALETYPE(*CLD) が指定されている場合には使用できません。 詳しくは、 CCSID とロケールについてを参照してください。

ワイド文字関数

詳しくは、 ワイド文字 を参照してください。

説明

towctrans() 関数は、 descによって記述されるマッピングを使用して、ワイド文字 wc をマップします。

towctrans(wc, wctrans("tolower")) は、ワイド文字の大/小文字マッピング関数 towlower()の呼び出しと同じように動作します。

towctrans(wc, wctrans("toupper")) は、ワイド文字の大/小文字マッピング関数 towupper()の呼び出しと同じように動作します。

戻り値

towctrans() 関数は、 descによって記述されるマッピングを使用して、 wc のマップされた値を戻します。

#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

*******************************************************************/

関連情報