]> pd.if.org Git - pdclib/blob - functions/wctype/towctrans.c
dos2unix
[pdclib] / functions / wctype / towctrans.c
1 /* towctrans( wint_t, wctrans_t )
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #include <wctype.h>
8 #ifndef REGTEST
9 #include <string.h>
10 #include "_PDCLIB_locale.h"
11
12 wint_t _PDCLIB_towctrans_l( wint_t wc, wctrans_t trans, locale_t l )
13 {
14     switch( trans ) {
15         case 0:                         return wc;
16         case _PDCLIB_WCTRANS_TOLOWER:   return _PDCLIB_towlower_l( wc, l );
17         case _PDCLIB_WCTRANS_TOUPPER:   return _PDCLIB_towupper_l( wc, l );
18         default: abort();
19     }
20 }
21
22 wint_t towctrans( wint_t wc, wctrans_t trans )
23 {
24     return _PDCLIB_towctrans_l( wc, trans, _PDCLIB_threadlocale() );
25 }
26
27 #endif
28
29 #ifdef TEST
30 #include "_PDCLIB_test.h"
31
32 int main( void )
33 {
34     TESTCASE(towctrans(L'a', wctrans("toupper")) == L'A');
35     TESTCASE(towctrans(L'B', wctrans("toupper")) == L'B');
36     TESTCASE(towctrans(L'a', wctrans("tolower")) == L'a');
37     TESTCASE(towctrans(L'B', wctrans("tolower")) == L'b');
38     TESTCASE(towctrans(L'B', wctrans("invalid")) == L'B');
39     TESTCASE(towctrans(L'B', 0)                  == L'B');
40     return TEST_RESULTS;
41 }
42 #endif