]> pd.if.org Git - pdclib/blob - functions/wctype/iswctype.c
PDCLIB-3 Add iswctype(3)
[pdclib] / functions / wctype / iswctype.c
1 /* iswctype( wint_t, wctype_t )\r
2 \r
3    This file is part of the Public Domain C Library (PDCLib).\r
4    Permission is granted to use, modify, and / or redistribute at will.\r
5 */\r
6 \r
7 #include <wctype.h>\r
8 #ifndef REGTEST\r
9 #include <_PDCLIB_locale.h>\r
10 \r
11 int iswctype( wint_t wc, wctype_t desc )\r
12 {\r
13     wc = _PDCLIB_unpackwint( wc );\r
14 \r
15     _PDCLIB_wcinfo_t *info = _PDCLIB_wcgetinfo( wc );\r
16 \r
17     if(!info) return 0;\r
18 \r
19     return info->flags & desc;\r
20 }\r
21 \r
22 #endif\r
23 \r
24 #ifdef TEST\r
25 #include <_PDCLIB_test.h>\r
26 \r
27 int main( void )\r
28 {\r
29     TESTCASE( iswctype(L'a', wctype("alpha")));\r
30     TESTCASE( iswctype(L'z', wctype("alpha")));\r
31     TESTCASE( iswctype(L'E', wctype("alpha")));\r
32     TESTCASE(!iswctype(L'3', wctype("alpha")));\r
33     TESTCASE(!iswctype(L';', wctype("alpha")));\r
34 \r
35     TESTCASE( iswctype(L'a', wctype("alnum")));\r
36     TESTCASE( iswctype(L'3', wctype("alnum")));\r
37     TESTCASE(!iswctype(L';', wctype("alnum")));\r
38 \r
39     TESTCASE( iswctype(L' ',  wctype("blank")));\r
40     TESTCASE( iswctype(L'\t', wctype("blank")));\r
41     TESTCASE(!iswctype(L'\n', wctype("blank")));\r
42     TESTCASE(!iswctype(L';',  wctype("blank")));\r
43 \r
44     TESTCASE( iswctype(L'\0', wctype("cntrl")));\r
45     TESTCASE( iswctype(L'\n', wctype("cntrl")));\r
46     TESTCASE( iswctype(L'\v', wctype("cntrl")));\r
47     TESTCASE(!iswctype(L'\t', wctype("cntrl")));\r
48     TESTCASE(!iswctype(L'a',  wctype("cntrl")));\r
49 \r
50     TESTCASE( iswctype(L'0',  wctype("digit")));\r
51     TESTCASE( iswctype(L'1',  wctype("digit")));\r
52     TESTCASE( iswctype(L'2',  wctype("digit")));\r
53     TESTCASE( iswctype(L'3',  wctype("digit")));\r
54     TESTCASE( iswctype(L'4',  wctype("digit")));\r
55     TESTCASE( iswctype(L'5',  wctype("digit")));\r
56     TESTCASE( iswctype(L'6',  wctype("digit")));\r
57     TESTCASE( iswctype(L'7',  wctype("digit")));\r
58     TESTCASE( iswctype(L'8',  wctype("digit")));\r
59     TESTCASE( iswctype(L'9',  wctype("digit")));\r
60     TESTCASE(!iswctype(L'X',  wctype("digit")));\r
61     TESTCASE(!iswctype(L'?',  wctype("digit")));\r
62 \r
63     TESTCASE( iswctype(L'a',  wctype("graph")));\r
64     TESTCASE( iswctype(L'z',  wctype("graph")));\r
65     TESTCASE( iswctype(L'E',  wctype("graph")));\r
66     TESTCASE( iswctype(L'E',  wctype("graph")));\r
67     TESTCASE(!iswctype(L' ',  wctype("graph")));\r
68     TESTCASE(!iswctype(L'\t', wctype("graph")));\r
69     TESTCASE(!iswctype(L'\n', wctype("graph")));\r
70 \r
71     TESTCASE( iswctype(L'a',  wctype("lower")));\r
72     TESTCASE( iswctype(L'e',  wctype("lower")));\r
73     TESTCASE( iswctype(L'z',  wctype("lower")));\r
74     TESTCASE(!iswctype(L'A',  wctype("lower")));\r
75     TESTCASE(!iswctype(L'E',  wctype("lower")));\r
76     TESTCASE(!iswctype(L'Z',  wctype("lower")));\r
77 \r
78     TESTCASE(!iswctype(L'a',  wctype("upper")));\r
79     TESTCASE(!iswctype(L'e',  wctype("upper")));\r
80     TESTCASE(!iswctype(L'z',  wctype("upper")));\r
81     TESTCASE( iswctype(L'A',  wctype("upper")));\r
82     TESTCASE( iswctype(L'E',  wctype("upper")));\r
83     TESTCASE( iswctype(L'Z',  wctype("upper")));\r
84 \r
85     TESTCASE( iswctype(L'Z',  wctype("print")));\r
86     TESTCASE( iswctype(L'a',  wctype("print")));\r
87     TESTCASE( iswctype(L';',  wctype("print")));\r
88     TESTCASE( iswctype(L'\t', wctype("print")));\r
89     TESTCASE(!iswctype(L'\0', wctype("print")));\r
90 \r
91     TESTCASE( iswctype(L';',  wctype("punct")));\r
92     TESTCASE( iswctype(L'.',  wctype("punct")));\r
93     TESTCASE( iswctype(L'?',  wctype("punct")));\r
94     TESTCASE(!iswctype(L' ',  wctype("punct")));\r
95     TESTCASE(!iswctype(L'Z',  wctype("punct")));\r
96 \r
97     TESTCASE( iswctype(L' ',  wctype("space")));\r
98     TESTCASE( iswctype(L'\t', wctype("space")));\r
99 \r
100     TESTCASE( iswctype(L'0',  wctype("xdigit")));\r
101     TESTCASE( iswctype(L'1',  wctype("xdigit")));\r
102     TESTCASE( iswctype(L'2',  wctype("xdigit")));\r
103     TESTCASE( iswctype(L'3',  wctype("xdigit")));\r
104     TESTCASE( iswctype(L'4',  wctype("xdigit")));\r
105     TESTCASE( iswctype(L'5',  wctype("xdigit")));\r
106     TESTCASE( iswctype(L'6',  wctype("xdigit")));\r
107     TESTCASE( iswctype(L'7',  wctype("xdigit")));\r
108     TESTCASE( iswctype(L'8',  wctype("xdigit")));\r
109     TESTCASE( iswctype(L'9',  wctype("xdigit")));\r
110     TESTCASE( iswctype(L'a',  wctype("xdigit")));\r
111     TESTCASE( iswctype(L'b',  wctype("xdigit")));\r
112     TESTCASE( iswctype(L'c',  wctype("xdigit")));\r
113     TESTCASE( iswctype(L'd',  wctype("xdigit")));\r
114     TESTCASE( iswctype(L'e',  wctype("xdigit")));\r
115     TESTCASE( iswctype(L'f',  wctype("xdigit")));\r
116     TESTCASE( iswctype(L'A',  wctype("xdigit")));\r
117     TESTCASE( iswctype(L'B',  wctype("xdigit")));\r
118     TESTCASE( iswctype(L'C',  wctype("xdigit")));\r
119     TESTCASE( iswctype(L'D',  wctype("xdigit")));\r
120     TESTCASE( iswctype(L'E',  wctype("xdigit")));\r
121     TESTCASE( iswctype(L'F',  wctype("xdigit")));\r
122     TESTCASE(!iswctype(L'g',  wctype("xdigit")));\r
123     TESTCASE(!iswctype(L'G',  wctype("xdigit")));\r
124     TESTCASE(!iswctype(L'x',  wctype("xdigit")));\r
125     TESTCASE(!iswctype(L'X',  wctype("xdigit")));\r
126     TESTCASE(!iswctype(L' ',  wctype("xdigit")));\r
127 \r
128     return TEST_RESULTS;\r
129 }\r
130 #endif\r