* MODULES.html.sh: New module wctype.
[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 /* iswctype, towctrans, towlower, towupper, wctrans, wctype,
22    wctrans_t, and wctype_t are not yet implemented.  */
23
24 #ifndef _GL_WCTYPE_H
25 #define _GL_WCTYPE_H
26
27 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
28    <wchar.h>.
29    BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before
30    <wchar.h>.  */
31 #include <stdio.h>
32 #include <time.h>
33 #include <wchar.h>
34
35 #if @HAVE_WCTYPE_H@
36 # include @ABSOLUTE_WCTYPE_H@
37 #endif
38
39 #if @HAVE_WCTYPE_CTMP_BUG@
40 static wint_t _ctmp_;
41 #endif
42
43 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
44    Assume all 12 functions are implemented the same way, or not at all.  */
45
46 #if !defined iswalnum && !HAVE_ISWCNTRL
47 static inline int
48 iswalnum (wint_t wc)
49 {
50   return ((wc >= '0' && wc <= '9')
51           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
52 }
53 # define iswalnum iswalnum
54 #endif
55
56 #if !defined iswalpha && !HAVE_ISWCNTRL
57 static inline int
58 iswalpha (wint_t wc)
59 {
60   return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
61 }
62 # define iswalpha iswalpha
63 #endif
64
65 #if !defined iswblank && !HAVE_ISWCNTRL
66 static inline int
67 iswblank (wint_t wc)
68 {
69   return wc == ' ' || wc == '\t';
70 }
71 # define iswblank iswblank
72 #endif
73
74 #if !defined iswcntrl && !HAVE_ISWCNTRL
75 static inline int
76 iswcntrl (wint_t wc)
77 {
78   return (wc & ~0x1f) == 0 || wc == 0x7f;
79 }
80 # define iswcntrl iswcntrl
81 #endif
82
83 #if !defined iswdigit && !HAVE_ISWCNTRL
84 static inline int
85 iswdigit (wint_t wc)
86 {
87   return wc >= '0' && wc <= '9';
88 }
89 # define iswdigit iswdigit
90 #endif
91
92 #if !defined iswgraph && !HAVE_ISWCNTRL
93 static inline int
94 iswgraph (wint_t wc)
95 {
96   return wc >= '!' && wc <= '~';
97 }
98 # define iswgraph iswgraph
99 #endif
100
101 #if !defined iswlower && !HAVE_ISWCNTRL
102 static inline int
103 iswlower (wint_t wc)
104 {
105   return wc >= 'a' && wc <= 'z';
106 }
107 # define iswlower iswlower
108 #endif
109
110 #if !defined iswprint && !HAVE_ISWCNTRL
111 static inline int
112 iswprint (wint_t wc)
113 {
114   return wc >= ' ' && wc <= '~';
115 }
116 # define iswprint iswprint
117 #endif
118
119 #if !defined iswpunct && !HAVE_ISWCNTRL
120 static inline int
121 iswpunct (wint_t wc)
122 {
123   return (wc >= '!' && wc <= '~'
124           && !((wc >= '0' && wc <= '9')
125                || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
126 }
127 # define iswpunct iswpunct
128 #endif
129
130 #if !defined iswspace && !HAVE_ISWCNTRL
131 static inline int
132 iswspace (wint_t wc)
133 {
134   return (wc == ' ' || wc == '\t'
135           || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
136 }
137 # define iswspace iswspace
138 #endif
139
140 #if !defined iswupper && !HAVE_ISWCNTRL
141 static inline int
142 iswupper (wint_t wc)
143 {
144   return wc >= 'A' && wc <= 'Z';
145 }
146 # define iswupper iswupper
147 #endif
148
149 #if !defined iswxdigit && !HAVE_ISWCNTRL
150 static inline int
151 iswxdigit (wint_t wc)
152 {
153   return ((wc >= '0' && wc <= '9')
154           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
155 }
156 # define iswxdigit iswxdigit
157 #endif
158
159
160 #endif /* _GL_WCTYPE_H */