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