+/* wctype( const char * )\r
+\r
+ This file is part of the Public Domain C Library (PDCLib).\r
+ Permission is granted to use, modify, and / or redistribute at will.\r
+*/\r
+\r
+#include <wctype.h>\r
+#ifndef REGTEST\r
+#include <string.h>\r
+#include <_PDCLIB_locale.h>\r
+\r
+wctype_t wctype( const char * property )\r
+{\r
+ if(property) switch(property[0])\r
+ {\r
+ case 'a':\r
+ if(strcmp(property, "alpha") == 0) {\r
+ return _PDCLIB_CTYPE_ALPHA;\r
+ } else if(strcmp(property, "alnum") == 0) {\r
+ return _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_DIGIT;\r
+ } else return 0;\r
+\r
+ case 'b':\r
+ if(strcmp(property, "blank") == 0) {\r
+ return _PDCLIB_CTYPE_BLANK;\r
+ } else return 0;\r
+\r
+ case 'c':\r
+ if(strcmp(property, "cntrl") == 0) {\r
+ return _PDCLIB_CTYPE_CNTRL;\r
+ } else return 0;\r
+\r
+ case 'd':\r
+ if(strcmp(property, "digit") == 0) {\r
+ return _PDCLIB_CTYPE_DIGIT;\r
+ } else return 0;\r
+\r
+ case 'g':\r
+ if(strcmp(property, "graph") == 0) {\r
+ return _PDCLIB_CTYPE_GRAPH;\r
+ } else return 0;\r
+\r
+ case 'l':\r
+ if(strcmp(property, "lower") == 0) {\r
+ return _PDCLIB_CTYPE_LOWER;\r
+ } else return 0;\r
+\r
+ case 'p':\r
+ if(strcmp(property, "print") == 0) {\r
+ return _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_SPACE;\r
+ } else if(strcmp(property, "punct") == 0) {\r
+ return _PDCLIB_CTYPE_PUNCT;\r
+ } else return 0;\r
+\r
+ case 's':\r
+ if(strcmp(property, "space") == 0) {\r
+ return _PDCLIB_CTYPE_SPACE;\r
+ } else return 0;\r
+\r
+ case 'u':\r
+ if(strcmp(property, "upper") == 0) {\r
+ return _PDCLIB_CTYPE_UPPER;\r
+ } else return 0;\r
+\r
+ case 'x':\r
+ if(strcmp(property, "xdigit") == 0) {\r
+ return _PDCLIB_CTYPE_XDIGT;\r
+ } else return 0;\r
+ }\r
+ return 0;\r
+}\r
+\r
+#endif\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+int main( void )\r
+{\r
+ TESTCASE(wctype("") == 0);\r
+ TESTCASE_NOREG(wctype(NULL) == 0); // mingw libc crashes on this\r
+\r
+ TESTCASE(wctype("alpha") != 0);\r
+ TESTCASE(wctype("alnum") != 0);\r
+ TESTCASE(wctype("blank") != 0);\r
+ TESTCASE(wctype("cntrl") != 0);\r
+ TESTCASE(wctype("digit") != 0);\r
+ TESTCASE(wctype("graph") != 0);\r
+ TESTCASE(wctype("lower") != 0);\r
+ TESTCASE(wctype("print") != 0);\r
+ TESTCASE(wctype("punct") != 0);\r
+ TESTCASE(wctype("space") != 0);\r
+ TESTCASE(wctype("upper") != 0);\r
+ TESTCASE(wctype("xdigit") != 0);\r
+\r
+ TESTCASE_NOREG(wctype("alpha") == _PDCLIB_CTYPE_ALPHA);\r
+ TESTCASE_NOREG(wctype("alnum") == _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_DIGIT);\r
+ TESTCASE_NOREG(wctype("blank") == _PDCLIB_CTYPE_BLANK);\r
+ TESTCASE_NOREG(wctype("cntrl") == _PDCLIB_CTYPE_CNTRL);\r
+ TESTCASE_NOREG(wctype("digit") == _PDCLIB_CTYPE_DIGIT);\r
+ TESTCASE_NOREG(wctype("graph") == _PDCLIB_CTYPE_GRAPH);\r
+ TESTCASE_NOREG(wctype("lower") == _PDCLIB_CTYPE_LOWER);\r
+ TESTCASE_NOREG(wctype("print") == _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_SPACE);\r
+ TESTCASE_NOREG(wctype("punct") == _PDCLIB_CTYPE_PUNCT);\r
+ TESTCASE_NOREG(wctype("space") == _PDCLIB_CTYPE_SPACE);\r
+ TESTCASE_NOREG(wctype("upper") == _PDCLIB_CTYPE_UPPER);\r
+ TESTCASE_NOREG(wctype("xdigit") == _PDCLIB_CTYPE_XDIGT);\r
+ return TEST_RESULTS;\r
+}\r
+#endif\r