towctrans() — Translate Wide Character
Format
#include <wctype.h>
wint_t towctrans(wint_t wc, wctrans_t desc);
Language Level
ANSI
Threadsafe
Yes
Locale Sensitive
The behavior of this function might be affected by the LC_CTYPE category of the current locale if LOCALETYPE(*LOCALE) is specified on the compilation command. It might also be affected by the LC_UNI_CTYPE category of the current locale if either the LOCALETYPE(*LOCALEUCS2) or LOCALETYPE(*LOCALEUTF) option is specified on the compilation command. This function is not available when LOCALETYPE(*CLD) is specified on the compilation command. For more information, see Understanding CCSIDs and Locales.
Wide Character Function
See Wide Characters for more information.
Description
The towctrans()
function
maps the wide character wc using the mapping that is described
by desc.
A towctrans(wc, wctrans("tolower"))
behaves
in the same way as the call to the wide-character, case-mapping function towlower()
.
A towctrans(wc, wctrans("toupper"))
behaves
in the same way as the call to the wide-character, case-mapping function towupper()
.
Return Value
The towctrans()
function
returns the mapped value of wc using the
mapping that is described by desc.
Example
#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
*******************************************************************/