From: Owen Shepherd Date: Sat, 16 Mar 2013 18:57:32 +0000 (+0000) Subject: PDCLIB-3 Add iswctype(3) X-Git-Url: https://pd.if.org/git/?p=pdclib.old;a=commitdiff_plain;h=17723aaba8dc3144b3b3699660714d34d71c3cd1 PDCLIB-3 Add iswctype(3) --- diff --git a/functions/wctype/iswctype.c b/functions/wctype/iswctype.c new file mode 100644 index 0000000..5c5f7ed --- /dev/null +++ b/functions/wctype/iswctype.c @@ -0,0 +1,130 @@ +/* iswctype( wint_t, wctype_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 <_PDCLIB_locale.h> + +int iswctype( wint_t wc, wctype_t desc ) +{ + wc = _PDCLIB_unpackwint( wc ); + + _PDCLIB_wcinfo_t *info = _PDCLIB_wcgetinfo( wc ); + + if(!info) return 0; + + return info->flags & desc; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + TESTCASE( iswctype(L'a', wctype("alpha"))); + TESTCASE( iswctype(L'z', wctype("alpha"))); + TESTCASE( iswctype(L'E', wctype("alpha"))); + TESTCASE(!iswctype(L'3', wctype("alpha"))); + TESTCASE(!iswctype(L';', wctype("alpha"))); + + TESTCASE( iswctype(L'a', wctype("alnum"))); + TESTCASE( iswctype(L'3', wctype("alnum"))); + TESTCASE(!iswctype(L';', wctype("alnum"))); + + TESTCASE( iswctype(L' ', wctype("blank"))); + TESTCASE( iswctype(L'\t', wctype("blank"))); + TESTCASE(!iswctype(L'\n', wctype("blank"))); + TESTCASE(!iswctype(L';', wctype("blank"))); + + TESTCASE( iswctype(L'\0', wctype("cntrl"))); + TESTCASE( iswctype(L'\n', wctype("cntrl"))); + TESTCASE( iswctype(L'\v', wctype("cntrl"))); + TESTCASE(!iswctype(L'\t', wctype("cntrl"))); + TESTCASE(!iswctype(L'a', wctype("cntrl"))); + + TESTCASE( iswctype(L'0', wctype("digit"))); + TESTCASE( iswctype(L'1', wctype("digit"))); + TESTCASE( iswctype(L'2', wctype("digit"))); + TESTCASE( iswctype(L'3', wctype("digit"))); + TESTCASE( iswctype(L'4', wctype("digit"))); + TESTCASE( iswctype(L'5', wctype("digit"))); + TESTCASE( iswctype(L'6', wctype("digit"))); + TESTCASE( iswctype(L'7', wctype("digit"))); + TESTCASE( iswctype(L'8', wctype("digit"))); + TESTCASE( iswctype(L'9', wctype("digit"))); + TESTCASE(!iswctype(L'X', wctype("digit"))); + TESTCASE(!iswctype(L'?', wctype("digit"))); + + TESTCASE( iswctype(L'a', wctype("graph"))); + TESTCASE( iswctype(L'z', wctype("graph"))); + TESTCASE( iswctype(L'E', wctype("graph"))); + TESTCASE( iswctype(L'E', wctype("graph"))); + TESTCASE(!iswctype(L' ', wctype("graph"))); + TESTCASE(!iswctype(L'\t', wctype("graph"))); + TESTCASE(!iswctype(L'\n', wctype("graph"))); + + TESTCASE( iswctype(L'a', wctype("lower"))); + TESTCASE( iswctype(L'e', wctype("lower"))); + TESTCASE( iswctype(L'z', wctype("lower"))); + TESTCASE(!iswctype(L'A', wctype("lower"))); + TESTCASE(!iswctype(L'E', wctype("lower"))); + TESTCASE(!iswctype(L'Z', wctype("lower"))); + + TESTCASE(!iswctype(L'a', wctype("upper"))); + TESTCASE(!iswctype(L'e', wctype("upper"))); + TESTCASE(!iswctype(L'z', wctype("upper"))); + TESTCASE( iswctype(L'A', wctype("upper"))); + TESTCASE( iswctype(L'E', wctype("upper"))); + TESTCASE( iswctype(L'Z', wctype("upper"))); + + TESTCASE( iswctype(L'Z', wctype("print"))); + TESTCASE( iswctype(L'a', wctype("print"))); + TESTCASE( iswctype(L';', wctype("print"))); + TESTCASE( iswctype(L'\t', wctype("print"))); + TESTCASE(!iswctype(L'\0', wctype("print"))); + + TESTCASE( iswctype(L';', wctype("punct"))); + TESTCASE( iswctype(L'.', wctype("punct"))); + TESTCASE( iswctype(L'?', wctype("punct"))); + TESTCASE(!iswctype(L' ', wctype("punct"))); + TESTCASE(!iswctype(L'Z', wctype("punct"))); + + TESTCASE( iswctype(L' ', wctype("space"))); + TESTCASE( iswctype(L'\t', wctype("space"))); + + TESTCASE( iswctype(L'0', wctype("xdigit"))); + TESTCASE( iswctype(L'1', wctype("xdigit"))); + TESTCASE( iswctype(L'2', wctype("xdigit"))); + TESTCASE( iswctype(L'3', wctype("xdigit"))); + TESTCASE( iswctype(L'4', wctype("xdigit"))); + TESTCASE( iswctype(L'5', wctype("xdigit"))); + TESTCASE( iswctype(L'6', wctype("xdigit"))); + TESTCASE( iswctype(L'7', wctype("xdigit"))); + TESTCASE( iswctype(L'8', wctype("xdigit"))); + TESTCASE( iswctype(L'9', wctype("xdigit"))); + TESTCASE( iswctype(L'a', wctype("xdigit"))); + TESTCASE( iswctype(L'b', wctype("xdigit"))); + TESTCASE( iswctype(L'c', wctype("xdigit"))); + TESTCASE( iswctype(L'd', wctype("xdigit"))); + TESTCASE( iswctype(L'e', wctype("xdigit"))); + TESTCASE( iswctype(L'f', wctype("xdigit"))); + TESTCASE( iswctype(L'A', wctype("xdigit"))); + TESTCASE( iswctype(L'B', wctype("xdigit"))); + TESTCASE( iswctype(L'C', wctype("xdigit"))); + TESTCASE( iswctype(L'D', wctype("xdigit"))); + TESTCASE( iswctype(L'E', wctype("xdigit"))); + TESTCASE( iswctype(L'F', wctype("xdigit"))); + TESTCASE(!iswctype(L'g', wctype("xdigit"))); + TESTCASE(!iswctype(L'G', wctype("xdigit"))); + TESTCASE(!iswctype(L'x', wctype("xdigit"))); + TESTCASE(!iswctype(L'X', wctype("xdigit"))); + TESTCASE(!iswctype(L' ', wctype("xdigit"))); + + return TEST_RESULTS; +} +#endif