2N/A/* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
2N/A
2N/A Copyright (C) 2006-2010 Free Software Foundation, Inc.
2N/A
2N/A This program is free software; you can redistribute it and/or modify
2N/A it under the terms of the GNU General Public License as published by
2N/A the Free Software Foundation; either version 3, or (at your option)
2N/A any later version.
2N/A
2N/A This program is distributed in the hope that it will be useful,
2N/A but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A GNU General Public License for more details.
2N/A
2N/A You should have received a copy of the GNU General Public License
2N/A along with this program; if not, write to the Free Software Foundation,
2N/A Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
2N/A
2N/A/* Written by Bruno Haible and Paul Eggert. */
2N/A
2N/A/*
2N/A * ISO C 99 <wctype.h> for platforms that lack it.
2N/A * <http://www.opengroup.org/susv3xbd/wctype.h.html>
2N/A *
2N/A * iswctype, towctrans, towlower, towupper, wctrans, wctype,
2N/A * wctrans_t, and wctype_t are not yet implemented.
2N/A */
2N/A
2N/A#ifndef _GL_WCTYPE_H
2N/A
2N/A#if __GNUC__ >= 3
2N/A@PRAGMA_SYSTEM_HEADER@
2N/A#endif
2N/A
2N/A#if @HAVE_WINT_T@
2N/A/* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.
2N/A Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
2N/A <wchar.h>.
2N/A BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
2N/A included before <wchar.h>. */
2N/A# include <stddef.h>
2N/A# include <stdio.h>
2N/A# include <time.h>
2N/A# include <wchar.h>
2N/A#endif
2N/A
2N/A/* Include the original <wctype.h> if it exists.
2N/A BeOS 5 has the functions but no <wctype.h>. */
2N/A/* The include_next requires a split double-inclusion guard. */
2N/A#if @HAVE_WCTYPE_H@
2N/A# @INCLUDE_NEXT@ @NEXT_WCTYPE_H@
2N/A#endif
2N/A
2N/A#ifndef _GL_WCTYPE_H
2N/A#define _GL_WCTYPE_H
2N/A
2N/A/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
2N/A
2N/A/* The definition of _GL_WARN_ON_USE is copied here. */
2N/A
2N/A/* Define wint_t and WEOF. (Also done in wchar.in.h.) */
2N/A#if !@HAVE_WINT_T@ && !defined wint_t
2N/A# define wint_t int
2N/A# ifndef WEOF
2N/A# define WEOF -1
2N/A# endif
2N/A#else
2N/A# ifndef WEOF
2N/A# define WEOF ((wint_t) -1)
2N/A# endif
2N/A#endif
2N/A
2N/A
2N/A/* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
2N/A Linux libc5 has <wctype.h> and the functions but they are broken.
2N/A Assume all 11 functions (all isw* except iswblank) are implemented the
2N/A same way, or not at all. */
2N/A#if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
2N/A
2N/A/* IRIX 5.3 has macros but no functions, its isw* macros refer to an
2N/A undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
2N/A refer to system functions like _iswctype that are not in the
2N/A standard C library. Rather than try to get ancient buggy
2N/A implementations like this to work, just disable them. */
2N/A# undef iswalnum
2N/A# undef iswalpha
2N/A# undef iswblank
2N/A# undef iswcntrl
2N/A# undef iswdigit
2N/A# undef iswgraph
2N/A# undef iswlower
2N/A# undef iswprint
2N/A# undef iswpunct
2N/A# undef iswspace
2N/A# undef iswupper
2N/A# undef iswxdigit
2N/A# undef towlower
2N/A# undef towupper
2N/A
2N/A/* Linux libc5 has <wctype.h> and the functions but they are broken. */
2N/A# if @REPLACE_ISWCNTRL@
2N/A# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2N/A# define iswalnum rpl_iswalnum
2N/A# define iswalpha rpl_iswalpha
2N/A# define iswblank rpl_iswblank
2N/A# define iswcntrl rpl_iswcntrl
2N/A# define iswdigit rpl_iswdigit
2N/A# define iswgraph rpl_iswgraph
2N/A# define iswlower rpl_iswlower
2N/A# define iswprint rpl_iswprint
2N/A# define iswpunct rpl_iswpunct
2N/A# define iswspace rpl_iswspace
2N/A# define iswupper rpl_iswupper
2N/A# define iswxdigit rpl_iswxdigit
2N/A# define towlower rpl_towlower
2N/A# define towupper rpl_towupper
2N/A# endif
2N/A# endif
2N/A
2N/Astatic inline int
2N/A# if @REPLACE_ISWCNTRL@
2N/Arpl_iswalnum
2N/A# else
2N/Aiswalnum
2N/A# endif
2N/A (wint_t wc)
2N/A{
2N/A return ((wc >= '0' && wc <= '9')
2N/A || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
2N/A}
2N/A
2N/Astatic inline int
2N/A# if @REPLACE_ISWCNTRL@
2N/Arpl_iswalpha
2N/A# else
2N/Aiswalpha
2N/A# endif
2N/A (wint_t wc)
2N/A{
2N/A return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
2N/A}
2N/A
2N/Astatic inline int
2N/A# if @REPLACE_ISWCNTRL@
2N/Arpl_iswblank
2N/A# else
2N/Aiswblank
2N/A# endif
2N/A (wint_t wc)
2N/A{
2N/A return wc == ' ' || wc == '\t';
2N/A}
2N/A
2N/Astatic inline int
2N/A# if @REPLACE_ISWCNTRL@
2N/Arpl_iswcntrl
2N/A# else
2N/Aiswcntrl
2N/A# endif
2N/A (wint_t wc)
2N/A{
2N/A return (wc & ~0x1f) == 0 || wc == 0x7f;
2N/A}
2N/A
2N/Astatic inline int
2N/A# if @REPLACE_ISWCNTRL@
2N/Arpl_iswdigit
2N/A# else
2N/Aiswdigit
2N/A# endif
2N/A (wint_t wc)
2N/A{
2N/A return wc >= '0' && wc <= '9';
2N/A}
2N/A
2N/Astatic inline int
2N/A# if @REPLACE_ISWCNTRL@
2N/Arpl_iswgraph
2N/A# else
2N/Aiswgraph
2N/A# endif
2N/A (wint_t wc)
2N/A{
2N/A return wc >= '!' && wc <= '~';
2N/A}
2N/A
2N/Astatic inline int
2N/A# if @REPLACE_ISWCNTRL@
2N/Arpl_iswlower
2N/A# else
2N/Aiswlower
2N/A# endif
2N/A (wint_t wc)
2N/A{
2N/A return wc >= 'a' && wc <= 'z';
2N/A}
2N/A
2N/Astatic inline int
2N/A# if @REPLACE_ISWCNTRL@
2N/Arpl_iswprint
2N/A# else
2N/Aiswprint
2N/A# endif
2N/A (wint_t wc)
2N/A{
2N/A return wc >= ' ' && wc <= '~';
2N/A}
2N/A
2N/Astatic inline int
2N/A# if @REPLACE_ISWCNTRL@
2N/Arpl_iswpunct
2N/A# else
2N/Aiswpunct
2N/A# endif
2N/A (wint_t wc)
2N/A{
2N/A return (wc >= '!' && wc <= '~'
2N/A && !((wc >= '0' && wc <= '9')
2N/A || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
2N/A}
2N/A
2N/Astatic inline int
2N/A# if @REPLACE_ISWCNTRL@
2N/Arpl_iswspace
2N/A# else
2N/Aiswspace
2N/A# endif
2N/A (wint_t wc)
2N/A{
2N/A return (wc == ' ' || wc == '\t'
2N/A || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
2N/A}
2N/A
2N/Astatic inline int
2N/A# if @REPLACE_ISWCNTRL@
2N/Arpl_iswupper
2N/A# else
2N/Aiswupper
2N/A# endif
2N/A (wint_t wc)
2N/A{
2N/A return wc >= 'A' && wc <= 'Z';
2N/A}
2N/A
2N/Astatic inline int
2N/A# if @REPLACE_ISWCNTRL@
2N/Arpl_iswxdigit
2N/A# else
2N/Aiswxdigit
2N/A# endif
2N/A (wint_t wc)
2N/A{
2N/A return ((wc >= '0' && wc <= '9')
2N/A || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
2N/A}
2N/A
2N/Astatic inline wint_t
2N/A# if @REPLACE_ISWCNTRL@
2N/Arpl_towlower
2N/A# else
2N/Atowlower
2N/A# endif
2N/A (wint_t wc)
2N/A{
2N/A return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc);
2N/A}
2N/A
2N/Astatic inline wint_t
2N/A# if @REPLACE_ISWCNTRL@
2N/Arpl_towupper
2N/A# else
2N/Atowupper
2N/A# endif
2N/A (wint_t wc)
2N/A{
2N/A return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc);
2N/A}
2N/A
2N/A#elif ! @HAVE_ISWBLANK@ || @REPLACE_ISWBLANK@
2N/A/* Only the iswblank function is missing. */
2N/A
2N/A# if @REPLACE_ISWBLANK@
2N/A# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2N/A# define iswblank rpl_iswblank
2N/A# endif
2N/A# endif
2N/A
2N/Astatic inline int
2N/A# if @REPLACE_ISWBLANK@
2N/Arpl_iswblank
2N/A# else
2N/Aiswblank
2N/A# endif
2N/A (wint_t wc)
2N/A{
2N/A return wc == ' ' || wc == '\t';
2N/A}
2N/A
2N/A#endif
2N/A
2N/A#if defined __MINGW32__
2N/A
2N/A/* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t.
2N/A The functions towlower and towupper are implemented in the MSVCRT library
2N/A to take a wchar_t argument and return a wchar_t result. mingw declares
2N/A these functions to take a wint_t argument and return a wint_t result.
2N/A This means that:
2N/A 1. When the user passes an argument outside the range 0x0000..0xFFFF, the
2N/A function will look only at the lower 16 bits. This is allowed according
2N/A to POSIX.
2N/A 2. The return value is returned in the lower 16 bits of the result register.
2N/A The upper 16 bits are random: whatever happened to be in that part of the
2N/A result register. We need to fix this by adding a zero-extend from
2N/A wchar_t to wint_t after the call. */
2N/A
2N/Astatic inline wint_t
2N/Arpl_towlower (wint_t wc)
2N/A{
2N/A return (wint_t) (wchar_t) towlower (wc);
2N/A}
2N/A# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2N/A# define towlower rpl_towlower
2N/A# endif
2N/A
2N/Astatic inline wint_t
2N/Arpl_towupper (wint_t wc)
2N/A{
2N/A return (wint_t) (wchar_t) towupper (wc);
2N/A}
2N/A# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2N/A# define towupper rpl_towupper
2N/A# endif
2N/A
2N/A#endif /* __MINGW32__ */
2N/A
2N/A#if @REPLACE_ISWCNTRL@
2N/A_GL_CXXALIAS_RPL (iswalnum, int, (wint_t wc));
2N/A_GL_CXXALIAS_RPL (iswalpha, int, (wint_t wc));
2N/A_GL_CXXALIAS_RPL (iswblank, int, (wint_t wc));
2N/A_GL_CXXALIAS_RPL (iswcntrl, int, (wint_t wc));
2N/A_GL_CXXALIAS_RPL (iswdigit, int, (wint_t wc));
2N/A_GL_CXXALIAS_RPL (iswgraph, int, (wint_t wc));
2N/A_GL_CXXALIAS_RPL (iswlower, int, (wint_t wc));
2N/A_GL_CXXALIAS_RPL (iswprint, int, (wint_t wc));
2N/A_GL_CXXALIAS_RPL (iswpunct, int, (wint_t wc));
2N/A_GL_CXXALIAS_RPL (iswspace, int, (wint_t wc));
2N/A_GL_CXXALIAS_RPL (iswupper, int, (wint_t wc));
2N/A_GL_CXXALIAS_RPL (iswxdigit, int, (wint_t wc));
2N/A#else
2N/A_GL_CXXALIAS_SYS (iswalnum, int, (wint_t wc));
2N/A_GL_CXXALIAS_SYS (iswalpha, int, (wint_t wc));
2N/A# if @REPLACE_ISWBLANK@
2N/A_GL_CXXALIAS_RPL (iswblank, int, (wint_t wc));
2N/A# else
2N/A_GL_CXXALIAS_SYS (iswblank, int, (wint_t wc));
2N/A# endif
2N/A_GL_CXXALIAS_SYS (iswcntrl, int, (wint_t wc));
2N/A_GL_CXXALIAS_SYS (iswdigit, int, (wint_t wc));
2N/A_GL_CXXALIAS_SYS (iswgraph, int, (wint_t wc));
2N/A_GL_CXXALIAS_SYS (iswlower, int, (wint_t wc));
2N/A_GL_CXXALIAS_SYS (iswprint, int, (wint_t wc));
2N/A_GL_CXXALIAS_SYS (iswpunct, int, (wint_t wc));
2N/A_GL_CXXALIAS_SYS (iswspace, int, (wint_t wc));
2N/A_GL_CXXALIAS_SYS (iswupper, int, (wint_t wc));
2N/A_GL_CXXALIAS_SYS (iswxdigit, int, (wint_t wc));
2N/A#endif
2N/A_GL_CXXALIASWARN (iswalnum);
2N/A_GL_CXXALIASWARN (iswalpha);
2N/A_GL_CXXALIASWARN (iswblank);
2N/A_GL_CXXALIASWARN (iswcntrl);
2N/A_GL_CXXALIASWARN (iswdigit);
2N/A_GL_CXXALIASWARN (iswgraph);
2N/A_GL_CXXALIASWARN (iswlower);
2N/A_GL_CXXALIASWARN (iswprint);
2N/A_GL_CXXALIASWARN (iswpunct);
2N/A_GL_CXXALIASWARN (iswspace);
2N/A_GL_CXXALIASWARN (iswupper);
2N/A_GL_CXXALIASWARN (iswxdigit);
2N/A
2N/A#if @REPLACE_ISWCNTRL@ || defined __MINGW32__
2N/A_GL_CXXALIAS_RPL (towlower, wint_t, (wint_t wc));
2N/A_GL_CXXALIAS_RPL (towupper, wint_t, (wint_t wc));
2N/A#else
2N/A_GL_CXXALIAS_SYS (towlower, wint_t, (wint_t wc));
2N/A_GL_CXXALIAS_SYS (towupper, wint_t, (wint_t wc));
2N/A#endif
2N/A_GL_CXXALIASWARN (towlower);
2N/A_GL_CXXALIASWARN (towupper);
2N/A
2N/A
2N/A#endif /* _GL_WCTYPE_H */
2N/A#endif /* _GL_WCTYPE_H */