1 /* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
3 Copyright (C) 2006 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.
33 /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.
34 Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
36 BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before
41 typedef wint_t __wctype_wint_t;
43 typedef int __wctype_wint_t;
46 /* Include the original <wctype.h> if it exists.
47 BeOS 5 has the functions but no <wctype.h>. */
49 # include @ABSOLUTE_WCTYPE_H@
52 /* IRIX 5.3 has bugs: its isw* macros refer to an undefined variable
53 _ctmp_ and to <ctype.h> macros like _P. */
54 #if @HAVE_WCTYPE_CTMP_BUG@
59 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
60 Assume all 12 functions are implemented the same way, or not at all. */
62 #if !defined iswalnum && !HAVE_ISWCNTRL
64 iswalnum (__wctype_wint_t wc)
66 return ((wc >= '0' && wc <= '9')
67 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
69 # define iswalnum iswalnum
72 #if !defined iswalpha && !HAVE_ISWCNTRL
74 iswalpha (__wctype_wint_t wc)
76 return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
78 # define iswalpha iswalpha
81 #if !defined iswblank && !HAVE_ISWCNTRL
83 iswblank (__wctype_wint_t wc)
85 return wc == ' ' || wc == '\t';
87 # define iswblank iswblank
90 #if !defined iswcntrl && !HAVE_ISWCNTRL
92 iswcntrl (__wctype_wint_t wc)
94 return (wc & ~0x1f) == 0 || wc == 0x7f;
96 # define iswcntrl iswcntrl
99 #if !defined iswdigit && !HAVE_ISWCNTRL
101 iswdigit (__wctype_wint_t wc)
103 return wc >= '0' && wc <= '9';
105 # define iswdigit iswdigit
108 #if !defined iswgraph && !HAVE_ISWCNTRL
110 iswgraph (__wctype_wint_t wc)
112 return wc >= '!' && wc <= '~';
114 # define iswgraph iswgraph
117 #if !defined iswlower && !HAVE_ISWCNTRL
119 iswlower (__wctype_wint_t wc)
121 return wc >= 'a' && wc <= 'z';
123 # define iswlower iswlower
126 #if !defined iswprint && !HAVE_ISWCNTRL
128 iswprint (__wctype_wint_t wc)
130 return wc >= ' ' && wc <= '~';
132 # define iswprint iswprint
135 #if !defined iswpunct && !HAVE_ISWCNTRL
137 iswpunct (__wctype_wint_t wc)
139 return (wc >= '!' && wc <= '~'
140 && !((wc >= '0' && wc <= '9')
141 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
143 # define iswpunct iswpunct
146 #if !defined iswspace && !HAVE_ISWCNTRL
148 iswspace (__wctype_wint_t wc)
150 return (wc == ' ' || wc == '\t'
151 || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
153 # define iswspace iswspace
156 #if !defined iswupper && !HAVE_ISWCNTRL
158 iswupper (__wctype_wint_t wc)
160 return wc >= 'A' && wc <= 'Z';
162 # define iswupper iswupper
165 #if !defined iswxdigit && !HAVE_ISWCNTRL
167 iswxdigit (__wctype_wint_t wc)
169 return ((wc >= '0' && wc <= '9')
170 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
172 # define iswxdigit iswxdigit
176 #endif /* _GL_WCTYPE_H */