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.
29 #ifndef _@GUARD_PREFIX@_WCTYPE_H
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@
55 #ifndef _@GUARD_PREFIX@_WCTYPE_H
56 #define _@GUARD_PREFIX@_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 /* Solaris 2.6 <wctype.h> includes <widec.h> which includes <euc.h> which
63 #defines a number of identifiers in the application namespace. Revert
75 /* Define wint_t and WEOF. (Also done in wchar.in.h.) */
76 #if !@HAVE_WINT_T@ && !defined wint_t
82 /* MSVC defines wint_t as 'unsigned short' in <crtdefs.h>.
83 This is too small: ISO C 99 section 7.24.1.(2) says that wint_t must be
84 "unchanged by default argument promotions". Override it. */
86 # if !GNULIB_defined_wint_t
88 typedef unsigned int rpl_wint_t;
90 # define wint_t rpl_wint_t
91 # define GNULIB_defined_wint_t 1
95 # define WEOF ((wint_t) -1)
100 #if !GNULIB_defined_wctype_functions
102 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
103 Linux libc5 has <wctype.h> and the functions but they are broken.
104 Assume all 11 functions (all isw* except iswblank) are implemented the
105 same way, or not at all. */
106 # if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
108 /* IRIX 5.3 has macros but no functions, its isw* macros refer to an
109 undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
110 refer to system functions like _iswctype that are not in the
111 standard C library. Rather than try to get ancient buggy
112 implementations like this to work, just disable them. */
128 /* Linux libc5 has <wctype.h> and the functions but they are broken. */
129 # if @REPLACE_ISWCNTRL@
130 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
131 # define iswalnum rpl_iswalnum
132 # define iswalpha rpl_iswalpha
133 # define iswblank rpl_iswblank
134 # define iswcntrl rpl_iswcntrl
135 # define iswdigit rpl_iswdigit
136 # define iswgraph rpl_iswgraph
137 # define iswlower rpl_iswlower
138 # define iswprint rpl_iswprint
139 # define iswpunct rpl_iswpunct
140 # define iswspace rpl_iswspace
141 # define iswupper rpl_iswupper
142 # define iswxdigit rpl_iswxdigit
145 # if @REPLACE_TOWLOWER@
146 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
147 # define towlower rpl_towlower
148 # define towupper rpl_towupper
153 # if @REPLACE_ISWCNTRL@
160 return ((wc >= '0' && wc <= '9')
161 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
165 # if @REPLACE_ISWCNTRL@
172 return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
176 # if @REPLACE_ISWCNTRL@
183 return wc == ' ' || wc == '\t';
187 # if @REPLACE_ISWCNTRL@
194 return (wc & ~0x1f) == 0 || wc == 0x7f;
198 # if @REPLACE_ISWCNTRL@
205 return wc >= '0' && wc <= '9';
209 # if @REPLACE_ISWCNTRL@
216 return wc >= '!' && wc <= '~';
220 # if @REPLACE_ISWCNTRL@
227 return wc >= 'a' && wc <= 'z';
231 # if @REPLACE_ISWCNTRL@
238 return wc >= ' ' && wc <= '~';
242 # if @REPLACE_ISWCNTRL@
249 return (wc >= '!' && wc <= '~'
250 && !((wc >= '0' && wc <= '9')
251 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
255 # if @REPLACE_ISWCNTRL@
262 return (wc == ' ' || wc == '\t'
263 || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
267 # if @REPLACE_ISWCNTRL@
274 return wc >= 'A' && wc <= 'Z';
278 # if @REPLACE_ISWCNTRL@
285 return ((wc >= '0' && wc <= '9')
286 || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
290 # if @REPLACE_TOWLOWER@
297 return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc);
301 # if @REPLACE_TOWLOWER@
308 return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc);
311 # elif @GNULIB_ISWBLANK@ && (! @HAVE_ISWBLANK@ || @REPLACE_ISWBLANK@)
312 /* Only the iswblank function is missing. */
314 # if @REPLACE_ISWBLANK@
315 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
316 # define iswblank rpl_iswblank
318 _GL_FUNCDECL_RPL (iswblank, int, (wint_t wc));
320 _GL_FUNCDECL_SYS (iswblank, int, (wint_t wc));
325 # if defined __MINGW32__
327 /* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t.
328 The functions towlower and towupper are implemented in the MSVCRT library
329 to take a wchar_t argument and return a wchar_t result. mingw declares
330 these functions to take a wint_t argument and return a wint_t result.
332 1. When the user passes an argument outside the range 0x0000..0xFFFF, the
333 function will look only at the lower 16 bits. This is allowed according
335 2. The return value is returned in the lower 16 bits of the result register.
336 The upper 16 bits are random: whatever happened to be in that part of the
337 result register. We need to fix this by adding a zero-extend from
338 wchar_t to wint_t after the call. */
341 rpl_towlower (wint_t wc)
343 return (wint_t) (wchar_t) towlower (wc);
345 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
346 # define towlower rpl_towlower
350 rpl_towupper (wint_t wc)
352 return (wint_t) (wchar_t) towupper (wc);
354 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
355 # define towupper rpl_towupper
358 # endif /* __MINGW32__ */
360 # define GNULIB_defined_wctype_functions 1
363 #if @REPLACE_ISWCNTRL@
364 _GL_CXXALIAS_RPL (iswalnum, int, (wint_t wc));
365 _GL_CXXALIAS_RPL (iswalpha, int, (wint_t wc));
366 _GL_CXXALIAS_RPL (iswcntrl, int, (wint_t wc));
367 _GL_CXXALIAS_RPL (iswdigit, int, (wint_t wc));
368 _GL_CXXALIAS_RPL (iswgraph, int, (wint_t wc));
369 _GL_CXXALIAS_RPL (iswlower, int, (wint_t wc));
370 _GL_CXXALIAS_RPL (iswprint, int, (wint_t wc));
371 _GL_CXXALIAS_RPL (iswpunct, int, (wint_t wc));
372 _GL_CXXALIAS_RPL (iswspace, int, (wint_t wc));
373 _GL_CXXALIAS_RPL (iswupper, int, (wint_t wc));
374 _GL_CXXALIAS_RPL (iswxdigit, int, (wint_t wc));
376 _GL_CXXALIAS_SYS (iswalnum, int, (wint_t wc));
377 _GL_CXXALIAS_SYS (iswalpha, int, (wint_t wc));
378 _GL_CXXALIAS_SYS (iswcntrl, int, (wint_t wc));
379 _GL_CXXALIAS_SYS (iswdigit, int, (wint_t wc));
380 _GL_CXXALIAS_SYS (iswgraph, int, (wint_t wc));
381 _GL_CXXALIAS_SYS (iswlower, int, (wint_t wc));
382 _GL_CXXALIAS_SYS (iswprint, int, (wint_t wc));
383 _GL_CXXALIAS_SYS (iswpunct, int, (wint_t wc));
384 _GL_CXXALIAS_SYS (iswspace, int, (wint_t wc));
385 _GL_CXXALIAS_SYS (iswupper, int, (wint_t wc));
386 _GL_CXXALIAS_SYS (iswxdigit, int, (wint_t wc));
388 _GL_CXXALIASWARN (iswalnum);
389 _GL_CXXALIASWARN (iswalpha);
390 _GL_CXXALIASWARN (iswcntrl);
391 _GL_CXXALIASWARN (iswdigit);
392 _GL_CXXALIASWARN (iswgraph);
393 _GL_CXXALIASWARN (iswlower);
394 _GL_CXXALIASWARN (iswprint);
395 _GL_CXXALIASWARN (iswpunct);
396 _GL_CXXALIASWARN (iswspace);
397 _GL_CXXALIASWARN (iswupper);
398 _GL_CXXALIASWARN (iswxdigit);
400 #if @GNULIB_ISWBLANK@
401 # if @REPLACE_ISWCNTRL@ || @REPLACE_ISWBLANK@
402 _GL_CXXALIAS_RPL (iswblank, int, (wint_t wc));
404 _GL_CXXALIAS_SYS (iswblank, int, (wint_t wc));
406 _GL_CXXALIASWARN (iswblank);
410 # if !GNULIB_defined_wctype_t
411 typedef void * wctype_t;
412 # define GNULIB_defined_wctype_t 1
416 /* Get a descriptor for a wide character property. */
418 # if !@HAVE_WCTYPE_T@
419 _GL_FUNCDECL_SYS (wctype, wctype_t, (const char *name));
421 _GL_CXXALIAS_SYS (wctype, wctype_t, (const char *name));
422 _GL_CXXALIASWARN (wctype);
423 #elif defined GNULIB_POSIXCHECK
425 # if HAVE_RAW_DECL_WCTYPE
426 _GL_WARN_ON_USE (wctype, "wctype is unportable - "
427 "use gnulib module wctype for portability");
431 /* Test whether a wide character has a given property.
432 The argument WC must be either a wchar_t value or WEOF.
433 The argument DESC must have been returned by the wctype() function. */
434 #if @GNULIB_ISWCTYPE@
435 # if !@HAVE_WCTYPE_T@
436 _GL_FUNCDECL_SYS (iswctype, int, (wint_t wc, wctype_t desc));
438 _GL_CXXALIAS_SYS (iswctype, int, (wint_t wc, wctype_t desc));
439 _GL_CXXALIASWARN (iswctype);
440 #elif defined GNULIB_POSIXCHECK
442 # if HAVE_RAW_DECL_ISWCTYPE
443 _GL_WARN_ON_USE (iswctype, "iswctype is unportable - "
444 "use gnulib module iswctype for portability");
448 #if @REPLACE_TOWLOWER@ || defined __MINGW32__
449 _GL_CXXALIAS_RPL (towlower, wint_t, (wint_t wc));
450 _GL_CXXALIAS_RPL (towupper, wint_t, (wint_t wc));
452 _GL_CXXALIAS_SYS (towlower, wint_t, (wint_t wc));
453 _GL_CXXALIAS_SYS (towupper, wint_t, (wint_t wc));
455 _GL_CXXALIASWARN (towlower);
456 _GL_CXXALIASWARN (towupper);
458 #if !@HAVE_WCTRANS_T@
459 # if !GNULIB_defined_wctrans_t
460 typedef void * wctrans_t;
461 # define GNULIB_defined_wctrans_t 1
465 /* Get a descriptor for a wide character case conversion. */
467 # if !@HAVE_WCTRANS_T@
468 _GL_FUNCDECL_SYS (wctrans, wctrans_t, (const char *name));
470 _GL_CXXALIAS_SYS (wctrans, wctrans_t, (const char *name));
471 _GL_CXXALIASWARN (wctrans);
472 #elif defined GNULIB_POSIXCHECK
474 # if HAVE_RAW_DECL_WCTRANS
475 _GL_WARN_ON_USE (wctrans, "wctrans is unportable - "
476 "use gnulib module wctrans for portability");
480 /* Perform a given case conversion on a wide character.
481 The argument WC must be either a wchar_t value or WEOF.
482 The argument DESC must have been returned by the wctrans() function. */
483 #if @GNULIB_TOWCTRANS@
484 # if !@HAVE_WCTRANS_T@
485 _GL_FUNCDECL_SYS (towctrans, wint_t, (wint_t wc, wctrans_t desc));
487 _GL_CXXALIAS_SYS (towctrans, wint_t, (wint_t wc, wctrans_t desc));
488 _GL_CXXALIASWARN (towctrans);
489 #elif defined GNULIB_POSIXCHECK
491 # if HAVE_RAW_DECL_TOWCTRANS
492 _GL_WARN_ON_USE (towctrans, "towctrans is unportable - "
493 "use gnulib module towctrans for portability");
498 #endif /* _@GUARD_PREFIX@_WCTYPE_H */
499 #endif /* _@GUARD_PREFIX@_WCTYPE_H */