iswctype.c revision 101985
1101369Stjr/*
2101369Stjr * Copyright (c) 1989, 1993
3101369Stjr *	The Regents of the University of California.  All rights reserved.
4101369Stjr * (c) UNIX System Laboratories, Inc.
5101369Stjr * All or some portions of this file are derived from material licensed
6101369Stjr * to the University of California by American Telephone and Telegraph
7101369Stjr * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8101369Stjr * the permission of UNIX System Laboratories, Inc.
9101369Stjr *
10101369Stjr * This code is derived from software contributed to Berkeley by
11101369Stjr * Paul Borman at Krystal Technologies.
12101369Stjr *
13101369Stjr * Redistribution and use in source and binary forms, with or without
14101369Stjr * modification, are permitted provided that the following conditions
15101369Stjr * are met:
16101369Stjr * 1. Redistributions of source code must retain the above copyright
17101369Stjr *    notice, this list of conditions and the following disclaimer.
18101369Stjr * 2. Redistributions in binary form must reproduce the above copyright
19101369Stjr *    notice, this list of conditions and the following disclaimer in the
20101369Stjr *    documentation and/or other materials provided with the distribution.
21101369Stjr * 3. All advertising materials mentioning features or use of this software
22101369Stjr *    must display the following acknowledgement:
23101369Stjr *	This product includes software developed by the University of
24101369Stjr *	California, Berkeley and its contributors.
25101369Stjr * 4. Neither the name of the University nor the names of its contributors
26101369Stjr *    may be used to endorse or promote products derived from this software
27101369Stjr *    without specific prior written permission.
28101369Stjr *
29101369Stjr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30101369Stjr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31101369Stjr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32101369Stjr * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33101369Stjr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34101369Stjr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35101369Stjr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36101369Stjr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37101369Stjr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38101369Stjr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39101369Stjr * SUCH DAMAGE.
40101369Stjr */
41101369Stjr
42101369Stjr#include <sys/cdefs.h>
43101369Stjr__FBSDID("$FreeBSD: head/lib/libc/locale/iswctype.c 101985 2002-08-16 13:45:23Z keichii $");
44101369Stjr
45101369Stjr#include <wctype.h>
46101369Stjr
47101369Stjr#undef iswalnum
48101369Stjrint
49101369Stjriswalnum(wc)
50101369Stjr	wint_t wc;
51101369Stjr{
52101369Stjr	return (__istype((wc), _CTYPE_A|_CTYPE_D));
53101369Stjr}
54101369Stjr
55101369Stjr#undef iswalpha
56101369Stjrint
57101369Stjriswalpha(wc)
58101369Stjr	wint_t wc;
59101369Stjr{
60101369Stjr	return (__istype((wc), _CTYPE_A));
61101369Stjr}
62101369Stjr
63101369Stjr#undef iswascii
64101369Stjrint
65101369Stjriswascii(wc)
66101369Stjr	wint_t wc;
67101369Stjr{
68101369Stjr	return (((wc) & ~0x7F) == 0);
69101369Stjr}
70101369Stjr
71101369Stjr#undef iswblank
72101369Stjrint
73101369Stjriswblank(wc)
74101369Stjr	wint_t wc;
75101369Stjr{
76101369Stjr	return (__istype((wc), _CTYPE_B));
77101369Stjr}
78101369Stjr
79101369Stjr#undef iswcntrl
80101369Stjrint
81101369Stjriswcntrl(wc)
82101369Stjr	wint_t wc;
83101369Stjr{
84101369Stjr	return (__istype((wc), _CTYPE_C));
85101369Stjr}
86101369Stjr
87101369Stjr#undef iswdigit
88101369Stjrint
89101369Stjriswdigit(wc)
90101369Stjr	wint_t wc;
91101369Stjr{
92101369Stjr	return (__isctype((wc), _CTYPE_D));
93101369Stjr}
94101369Stjr
95101369Stjr#undef iswgraph
96101369Stjrint
97101369Stjriswgraph(wc)
98101369Stjr	wint_t wc;
99101369Stjr{
100101369Stjr	return (__istype((wc), _CTYPE_G));
101101369Stjr}
102101369Stjr
103101369Stjr#undef iswhexnumber
104101369Stjrint
105101369Stjriswhexnumber(wc)
106101369Stjr	wint_t wc;
107101369Stjr{
108101369Stjr	return (__istype((wc), _CTYPE_X));
109101369Stjr}
110101369Stjr
111101369Stjr#undef iswideogram
112101369Stjrint
113101369Stjriswideogram(wc)
114101369Stjr	wint_t wc;
115101369Stjr{
116101369Stjr	return (__istype((wc), _CTYPE_I));
117101369Stjr}
118101369Stjr
119101369Stjr#undef iswlower
120101369Stjrint
121101369Stjriswlower(wc)
122101369Stjr	wint_t wc;
123101369Stjr{
124101369Stjr	return (__istype((wc), _CTYPE_L));
125101369Stjr}
126101369Stjr
127101369Stjr#undef iswnumber
128101369Stjrint
129101369Stjriswnumber(wc)
130101369Stjr	wint_t wc;
131101369Stjr{
132101369Stjr	return (__istype((wc), _CTYPE_D));
133101369Stjr}
134101369Stjr
135101369Stjr#undef iswphonogram
136101369Stjrint
137101369Stjriswphonogram(wc)
138101369Stjr	wint_t wc;
139101369Stjr{
140101369Stjr	return (__istype((wc), _CTYPE_Q));
141101369Stjr}
142101369Stjr
143101369Stjr#undef iswprint
144101369Stjrint
145101369Stjriswprint(wc)
146101369Stjr	wint_t wc;
147101369Stjr{
148101369Stjr	return (__istype((wc), _CTYPE_R));
149101369Stjr}
150101369Stjr
151101369Stjr#undef iswpunct
152101369Stjrint
153101369Stjriswpunct(wc)
154101369Stjr	wint_t wc;
155101369Stjr{
156101369Stjr	return (__istype((wc), _CTYPE_P));
157101369Stjr}
158101369Stjr
159101369Stjr#undef iswrune
160101369Stjrint
161101369Stjriswrune(wc)
162101369Stjr	wint_t wc;
163101369Stjr{
164101369Stjr	return (__istype((wc), 0xFFFFFF00L));
165101369Stjr}
166101369Stjr
167101369Stjr#undef iswspace
168101369Stjrint
169101369Stjriswspace(wc)
170101369Stjr	wint_t wc;
171101369Stjr{
172101369Stjr	return (__istype((wc), _CTYPE_S));
173101369Stjr}
174101369Stjr
175101369Stjr#undef iswspecial
176101369Stjrint
177101369Stjriswspecial(wc)
178101369Stjr	wint_t wc;
179101369Stjr{
180101369Stjr	return (__istype((wc), _CTYPE_T));
181101369Stjr}
182101369Stjr
183101369Stjr#undef iswupper
184101369Stjrint
185101369Stjriswupper(wc)
186101369Stjr	wint_t wc;
187101369Stjr{
188101369Stjr	return (__istype((wc), _CTYPE_U));
189101369Stjr}
190101369Stjr
191101369Stjr#undef iswxdigit
192101369Stjrint
193101369Stjriswxdigit(wc)
194101369Stjr	wint_t wc;
195101369Stjr{
196101369Stjr	return (__isctype((wc), _CTYPE_X));
197101369Stjr}
198101369Stjr
199101369Stjr#undef towlower
200101369Stjrwint_t
201101369Stjrtowlower(wc)
202101369Stjr	wint_t wc;
203101369Stjr{
204101369Stjr        return (__tolower(wc));
205101369Stjr}
206101369Stjr
207101369Stjr#undef towupper
208101369Stjrwint_t
209101369Stjrtowupper(wc)
210101369Stjr	wint_t wc;
211101369Stjr{
212101369Stjr        return (__toupper(wc));
213101369Stjr}
214101985Skeichii
215101985Skeichii#undef wcwidth
216101985Skeichiiint
217101985Skeichiiwcwidth(wc)
218101985Skeichii        wchar_t wc;
219101985Skeichii{
220101985Skeichii	int width = (unsigned)__maskrune((wc), _CTYPE_SWM) >> _CTYPE_SWS;
221101985Skeichii	return width ? width : iswprint(wc);
222101985Skeichii}
223101985Skeichii
224