From: Owen Shepherd Date: Sat, 16 Mar 2013 20:33:00 +0000 (+0000) Subject: PDCLIB-3 #resolve Implement towctrans/wctrans. Completes wctype.h X-Git-Url: https://pd.if.org/git/?p=pdclib;a=commitdiff_plain;h=6e6c4e6b52f2516e4bb6b9f37c1e2e18cb7448b5 PDCLIB-3 #resolve Implement towctrans/wctrans. Completes wctype.h --- 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 diff --git a/functions/wctype/wctrans.c b/functions/wctype/wctrans.c new file mode 100644 index 0000000..31f36be --- /dev/null +++ b/functions/wctype/wctrans.c @@ -0,0 +1,38 @@ +/* wctrans( const char * ) + + 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> + +wctrans_t wctrans( const char * property ) +{ + if(!property) { + return 0; + } else if(strcmp(property, "tolower") == 0) { + return _PDCLIB_WCTRANS_TOLOWER; + } else if(strcmp(property, "toupper") == 0) { + return _PDCLIB_WCTRANS_TOUPPER; + } else { + return 0; + } +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + TESTCASE(wctrans("") == 0); + TESTCASE(wctrans("invalid") == 0); + TESTCASE(wctrans("toupper") != 0); + TESTCASE(wctrans("tolower") != 0); + return TEST_RESULTS; +} +#endif diff --git a/internals/_PDCLIB_locale.h b/internals/_PDCLIB_locale.h index dbedc80..3b2dece 100644 --- a/internals/_PDCLIB_locale.h +++ b/internals/_PDCLIB_locale.h @@ -59,6 +59,9 @@ #define _PDCLIB_CTYPE_DIGIT 256 #define _PDCLIB_CTYPE_XDIGT 512 +#define _PDCLIB_WCTRANS_TOLOWER 1 +#define _PDCLIB_WCTRANS_TOUPPER 2 + typedef struct _PDCLIB_ctype { _PDCLIB_uint16_t flags;