1 /* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
3 Copyright (C) 2006-2011 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@
37 /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.
38 Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
40 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
41 included before <wchar.h>. */
48 /* Include the original <wctype.h> if it exists.
49 BeOS 5 has the functions but no <wctype.h>. */
50 /* The include_next requires a split double-inclusion guard. */
52 # @INCLUDE_NEXT@ @NEXT_WCTYPE_H@
58 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
60 /* The definition of _GL_WARN_ON_USE is copied here. */
62 /* Define wint_t and WEOF. (Also done in wchar.in.h.) */
63 #if !@HAVE_WINT_T@ && !defined wint_t
70 # define WEOF ((wint_t) -1)
75 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
76 Linux libc5 has <wctype.h> and the functions but they are broken.
77 Assume all 11 functions (all isw* except iswblank) are implemented the
78 same way, or not at all. */
79 #if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
81 /* IRIX 5.3 has macros but no functions, its isw* macros refer to an
82 undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
83 refer to system functions like _iswctype that are not in the
84 standard C library. Rather than try to get ancient buggy
85 implementations like this to work, just disable them. */
101 /* Linux libc5 has <wctype.h> and the functions but they are broken. */
102 # if @REPLACE_ISWCNTRL@
103 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
104 # define iswalnum rpl_iswalnum
105 # define iswalpha rpl_iswalpha
106 # define iswblank rpl_iswblank
107 # define iswcntrl rpl_iswcntrl
108 # define iswdigit rpl_iswdigit
109 # define iswgraph rpl_iswgraph
110 # define iswlower rpl_iswlower
111 # define iswprint rpl_iswprint
112 # define iswpunct rpl_iswpunct
113 # define iswspace rpl_iswspace
114 # define iswupper rpl_iswupper
115 # define iswxdigit rpl_iswxdigit
116 # define towlower rpl_towlower
117 # define towupper rpl_towupper
122 # if @REPLACE_ISWCNTRL@
129 return ((wc >= '0' && wc <= '9')
130 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
134 # if @REPLACE_ISWCNTRL@
141 return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
145 # if @REPLACE_ISWCNTRL@
152 return wc == ' ' || wc == '\t';
156 # if @REPLACE_ISWCNTRL@
163 return (wc & ~0x1f) == 0 || wc == 0x7f;
167 # if @REPLACE_ISWCNTRL@
174 return wc >= '0' && wc <= '9';
178 # if @REPLACE_ISWCNTRL@
185 return wc >= '!' && wc <= '~';
189 # if @REPLACE_ISWCNTRL@
196 return wc >= 'a' && wc <= 'z';
200 # if @REPLACE_ISWCNTRL@
207 return wc >= ' ' && wc <= '~';
211 # if @REPLACE_ISWCNTRL@
218 return (wc >= '!' && wc <= '~'
219 && !((wc >= '0' && wc <= '9')
220 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
224 # if @REPLACE_ISWCNTRL@
231 return (wc == ' ' || wc == '\t'
232 || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
236 # if @REPLACE_ISWCNTRL@
243 return wc >= 'A' && wc <= 'Z';
247 # if @REPLACE_ISWCNTRL@
254 return ((wc >= '0' && wc <= '9')
255 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
259 # if @REPLACE_ISWCNTRL@
266 return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc);
270 # if @REPLACE_ISWCNTRL@
277 return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc);
280 #elif ! @HAVE_ISWBLANK@ || @REPLACE_ISWBLANK@
281 /* Only the iswblank function is missing. */
283 # if @REPLACE_ISWBLANK@
284 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
285 # define iswblank rpl_iswblank
287 _GL_FUNCDECL_RPL (iswblank, int, (wint_t wc));
289 _GL_FUNCDECL_SYS (iswblank, int, (wint_t wc));
294 #if defined __MINGW32__
296 /* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t.
297 The functions towlower and towupper are implemented in the MSVCRT library
298 to take a wchar_t argument and return a wchar_t result. mingw declares
299 these functions to take a wint_t argument and return a wint_t result.
301 1. When the user passes an argument outside the range 0x0000..0xFFFF, the
302 function will look only at the lower 16 bits. This is allowed according
304 2. The return value is returned in the lower 16 bits of the result register.
305 The upper 16 bits are random: whatever happened to be in that part of the
306 result register. We need to fix this by adding a zero-extend from
307 wchar_t to wint_t after the call. */
310 rpl_towlower (wint_t wc)
312 return (wint_t) (wchar_t) towlower (wc);
314 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
315 # define towlower rpl_towlower
319 rpl_towupper (wint_t wc)
321 return (wint_t) (wchar_t) towupper (wc);
323 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
324 # define towupper rpl_towupper
327 #endif /* __MINGW32__ */
329 #if @REPLACE_ISWCNTRL@
330 _GL_CXXALIAS_RPL (iswalnum, int, (wint_t wc));
331 _GL_CXXALIAS_RPL (iswalpha, int, (wint_t wc));
332 _GL_CXXALIAS_RPL (iswblank, int, (wint_t wc));
333 _GL_CXXALIAS_RPL (iswcntrl, int, (wint_t wc));
334 _GL_CXXALIAS_RPL (iswdigit, int, (wint_t wc));
335 _GL_CXXALIAS_RPL (iswgraph, int, (wint_t wc));
336 _GL_CXXALIAS_RPL (iswlower, int, (wint_t wc));
337 _GL_CXXALIAS_RPL (iswprint, int, (wint_t wc));
338 _GL_CXXALIAS_RPL (iswpunct, int, (wint_t wc));
339 _GL_CXXALIAS_RPL (iswspace, int, (wint_t wc));
340 _GL_CXXALIAS_RPL (iswupper, int, (wint_t wc));
341 _GL_CXXALIAS_RPL (iswxdigit, int, (wint_t wc));
343 _GL_CXXALIAS_SYS (iswalnum, int, (wint_t wc));
344 _GL_CXXALIAS_SYS (iswalpha, int, (wint_t wc));
345 # if @REPLACE_ISWBLANK@
346 _GL_CXXALIAS_RPL (iswblank, int, (wint_t wc));
348 _GL_CXXALIAS_SYS (iswblank, int, (wint_t wc));
350 _GL_CXXALIAS_SYS (iswcntrl, int, (wint_t wc));
351 _GL_CXXALIAS_SYS (iswdigit, int, (wint_t wc));
352 _GL_CXXALIAS_SYS (iswgraph, int, (wint_t wc));
353 _GL_CXXALIAS_SYS (iswlower, int, (wint_t wc));
354 _GL_CXXALIAS_SYS (iswprint, int, (wint_t wc));
355 _GL_CXXALIAS_SYS (iswpunct, int, (wint_t wc));
356 _GL_CXXALIAS_SYS (iswspace, int, (wint_t wc));
357 _GL_CXXALIAS_SYS (iswupper, int, (wint_t wc));
358 _GL_CXXALIAS_SYS (iswxdigit, int, (wint_t wc));
360 _GL_CXXALIASWARN (iswalnum);
361 _GL_CXXALIASWARN (iswalpha);
362 _GL_CXXALIASWARN (iswblank);
363 _GL_CXXALIASWARN (iswcntrl);
364 _GL_CXXALIASWARN (iswdigit);
365 _GL_CXXALIASWARN (iswgraph);
366 _GL_CXXALIASWARN (iswlower);
367 _GL_CXXALIASWARN (iswprint);
368 _GL_CXXALIASWARN (iswpunct);
369 _GL_CXXALIASWARN (iswspace);
370 _GL_CXXALIASWARN (iswupper);
371 _GL_CXXALIASWARN (iswxdigit);
373 #if @REPLACE_ISWCNTRL@ || defined __MINGW32__
374 _GL_CXXALIAS_RPL (towlower, wint_t, (wint_t wc));
375 _GL_CXXALIAS_RPL (towupper, wint_t, (wint_t wc));
377 _GL_CXXALIAS_SYS (towlower, wint_t, (wint_t wc));
378 _GL_CXXALIAS_SYS (towupper, wint_t, (wint_t wc));
380 _GL_CXXALIASWARN (towlower);
381 _GL_CXXALIASWARN (towupper);
384 #endif /* _GL_WCTYPE_H */
385 #endif /* _GL_WCTYPE_H */