1 /* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
3 Copyright (C) 2006-2009 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 /* Written by Bruno Haible and Paul Eggert. */
22 * ISO C 99 <wctype.h> for platforms that lack it.
23 * <http://www.opengroup.org/susv3xbd/wctype.h.html>
25 * iswctype, towctrans, towlower, towupper, wctrans, wctype,
26 * wctrans_t, and wctype_t are not yet implemented.
32 @PRAGMA_SYSTEM_HEADER@
36 /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.
37 Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
39 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
40 included before <wchar.h>. */
47 /* Include the original <wctype.h> if it exists.
48 BeOS 5 has the functions but no <wctype.h>. */
49 /* The include_next requires a split double-inclusion guard. */
51 # @INCLUDE_NEXT@ @NEXT_WCTYPE_H@
57 /* Define wint_t. (Also done in wchar.in.h.) */
58 #if !@HAVE_WINT_T@ && !defined wint_t
65 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
66 Linux libc5 has <wctype.h> and the functions but they are broken.
67 Assume all 12 functions are implemented the same way, or not at all. */
68 #if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
70 /* IRIX 5.3 has macros but no functions, its isw* macros refer to an
71 undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
72 refer to system functions like _iswctype that are not in the
73 standard C library. Rather than try to get ancient buggy
74 implementations like this to work, just disable them. */
90 /* Linux libc5 has <wctype.h> and the functions but they are broken. */
91 # if @REPLACE_ISWCNTRL@
92 # define iswalnum rpl_iswalnum
93 # define iswalpha rpl_iswalpha
94 # define iswblank rpl_iswblank
95 # define iswcntrl rpl_iswcntrl
96 # define iswdigit rpl_iswdigit
97 # define iswgraph rpl_iswgraph
98 # define iswlower rpl_iswlower
99 # define iswprint rpl_iswprint
100 # define iswpunct rpl_iswpunct
101 # define iswspace rpl_iswspace
102 # define iswupper rpl_iswupper
103 # define iswxdigit rpl_iswxdigit
104 # define towlower rpl_towlower
105 # define towupper rpl_towupper
111 return ((wc >= '0' && wc <= '9')
112 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
118 return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
124 return wc == ' ' || wc == '\t';
130 return (wc & ~0x1f) == 0 || wc == 0x7f;
136 return wc >= '0' && wc <= '9';
142 return wc >= '!' && wc <= '~';
148 return wc >= 'a' && wc <= 'z';
154 return wc >= ' ' && wc <= '~';
160 return (wc >= '!' && wc <= '~'
161 && !((wc >= '0' && wc <= '9')
162 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
168 return (wc == ' ' || wc == '\t'
169 || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
175 return wc >= 'A' && wc <= 'Z';
179 iswxdigit (wint_t wc)
181 return ((wc >= '0' && wc <= '9')
182 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
188 return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc);
194 return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc);
197 # endif /* ! HAVE_ISWCNTRL */
199 # if defined __MINGW32__
201 /* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t.
202 The functions towlower and towupper are implemented in the MSVCRT library
203 to take a wchar_t argument and return a wchar_t result. mingw declares
204 these functions to take a wint_t argument and return a wint_t result.
206 1. When the user passes an argument outside the range 0x0000..0xFFFF, the
207 function will look only at the lower 16 bits. This is allowed according
209 2. The return value is returned in the lower 16 bits of the result register.
210 The upper 16 bits are random: whatever happened to be in that part of the
211 result register. We need to fix this by adding a zero-extend from
212 wchar_t to wint_t after the call. */
215 rpl_towlower (wint_t wc)
217 return (wint_t) (wchar_t) towlower (wc);
219 # define towlower rpl_towlower
222 rpl_towupper (wint_t wc)
224 return (wint_t) (wchar_t) towupper (wc);
226 # define towupper rpl_towupper
230 #endif /* _GL_WCTYPE_H */
231 #endif /* _GL_WCTYPE_H */