Add comments.
[gnulib.git] / lib / wctype_.h
1 /* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
2
3    Copyright (C) 2006 Free Software Foundation, Inc.
4
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)
8    any later version.
9
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.
14
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.  */
18
19 /* Written by Bruno Haible and Paul Eggert.  */
20
21 /*
22  * ISO C 99 <wctype.h> for platforms that lack it.
23  * <http://www.opengroup.org/susv3xbd/wctype.h.html>
24  *
25  * iswctype, towctrans, towlower, towupper, wctrans, wctype,
26  * wctrans_t, and wctype_t are not yet implemented.
27  */
28
29 #ifndef _GL_WCTYPE_H
30 #define _GL_WCTYPE_H
31
32 /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.
33    Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
34    <wchar.h>.
35    BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before
36    <wchar.h>.  */
37 #include <stdio.h>
38 #include <time.h>
39 #include <wchar.h>
40
41 /* Include the original <wctype.h> if it exists.
42    BeOS 5 has the functions but no <wctype.h>.  */
43 #if @HAVE_WCTYPE_H@
44 # include @ABSOLUTE_WCTYPE_H@
45 #endif
46
47 /* IRIX 5.3 has a bug: its isw* macros reference an undefined variable
48    _ctmp_.  */
49 #if @HAVE_WCTYPE_CTMP_BUG@
50 static wint_t _ctmp_;
51 #endif
52
53 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
54    Assume all 12 functions are implemented the same way, or not at all.  */
55
56 #if !defined iswalnum && !HAVE_ISWCNTRL
57 static inline int
58 iswalnum (wint_t wc)
59 {
60   return ((wc >= '0' && wc <= '9')
61           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
62 }
63 # define iswalnum iswalnum
64 #endif
65
66 #if !defined iswalpha && !HAVE_ISWCNTRL
67 static inline int
68 iswalpha (wint_t wc)
69 {
70   return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
71 }
72 # define iswalpha iswalpha
73 #endif
74
75 #if !defined iswblank && !HAVE_ISWCNTRL
76 static inline int
77 iswblank (wint_t wc)
78 {
79   return wc == ' ' || wc == '\t';
80 }
81 # define iswblank iswblank
82 #endif
83
84 #if !defined iswcntrl && !HAVE_ISWCNTRL
85 static inline int
86 iswcntrl (wint_t wc)
87 {
88   return (wc & ~0x1f) == 0 || wc == 0x7f;
89 }
90 # define iswcntrl iswcntrl
91 #endif
92
93 #if !defined iswdigit && !HAVE_ISWCNTRL
94 static inline int
95 iswdigit (wint_t wc)
96 {
97   return wc >= '0' && wc <= '9';
98 }
99 # define iswdigit iswdigit
100 #endif
101
102 #if !defined iswgraph && !HAVE_ISWCNTRL
103 static inline int
104 iswgraph (wint_t wc)
105 {
106   return wc >= '!' && wc <= '~';
107 }
108 # define iswgraph iswgraph
109 #endif
110
111 #if !defined iswlower && !HAVE_ISWCNTRL
112 static inline int
113 iswlower (wint_t wc)
114 {
115   return wc >= 'a' && wc <= 'z';
116 }
117 # define iswlower iswlower
118 #endif
119
120 #if !defined iswprint && !HAVE_ISWCNTRL
121 static inline int
122 iswprint (wint_t wc)
123 {
124   return wc >= ' ' && wc <= '~';
125 }
126 # define iswprint iswprint
127 #endif
128
129 #if !defined iswpunct && !HAVE_ISWCNTRL
130 static inline int
131 iswpunct (wint_t wc)
132 {
133   return (wc >= '!' && wc <= '~'
134           && !((wc >= '0' && wc <= '9')
135                || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
136 }
137 # define iswpunct iswpunct
138 #endif
139
140 #if !defined iswspace && !HAVE_ISWCNTRL
141 static inline int
142 iswspace (wint_t wc)
143 {
144   return (wc == ' ' || wc == '\t'
145           || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
146 }
147 # define iswspace iswspace
148 #endif
149
150 #if !defined iswupper && !HAVE_ISWCNTRL
151 static inline int
152 iswupper (wint_t wc)
153 {
154   return wc >= 'A' && wc <= 'Z';
155 }
156 # define iswupper iswupper
157 #endif
158
159 #if !defined iswxdigit && !HAVE_ISWCNTRL
160 static inline int
161 iswxdigit (wint_t wc)
162 {
163   return ((wc >= '0' && wc <= '9')
164           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
165 }
166 # define iswxdigit iswxdigit
167 #endif
168
169
170 #endif /* _GL_WCTYPE_H */