X-Git-Url: https://pd.if.org/git/?p=pdclib.old;a=blobdiff_plain;f=functions%2Fwctype%2Ftowctrans.c;fp=functions%2Fwctype%2Ftowctrans.c;h=aea9b1a303ae28474e1d58435cdb917e7be91b91;hp=0000000000000000000000000000000000000000;hb=24f274eec4d6ac3868f3fdf03d2e1876c80be616;hpb=b641165a0d122178a33070e3434ab7b49397ad94 diff --git a/functions/wctype/towctrans.c b/functions/wctype/towctrans.c new file mode 100644 index 0000000..aea9b1a --- /dev/null +++ b/functions/wctype/towctrans.c @@ -0,0 +1,37 @@ +/* towctrans( wint_t, wctrans_t ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include +#ifndef REGTEST +#include +#include <_PDCLIB_locale.h> + +wint_t towctrans( wint_t wc, wctrans_t trans ) +{ + switch( trans ) { + case 0: return wc; + case _PDCLIB_WCTRANS_TOLOWER: return towlower( wc ); + case _PDCLIB_WCTRANS_TOUPPER: return towupper( wc ); + default: abort(); + } +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + TESTCASE(towctrans(L'a', wctrans("toupper")) == L'A'); + TESTCASE(towctrans(L'B', wctrans("toupper")) == L'B'); + TESTCASE(towctrans(L'a', wctrans("tolower")) == L'a'); + TESTCASE(towctrans(L'B', wctrans("tolower")) == L'b'); + TESTCASE(towctrans(L'B', wctrans("invalid")) == L'B'); + TESTCASE(towctrans(L'B', 0) == L'B'); + return TEST_RESULTS; +} +#endif