4
0

wctype.in.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
  2. Copyright (C) 2006-2008 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software Foundation,
  13. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  14. /* Written by Bruno Haible and Paul Eggert. */
  15. /*
  16. * ISO C 99 <wctype.h> for platforms that lack it.
  17. * <http://www.opengroup.org/susv3xbd/wctype.h.html>
  18. *
  19. * iswctype, towctrans, towlower, towupper, wctrans, wctype,
  20. * wctrans_t, and wctype_t are not yet implemented.
  21. */
  22. #ifndef _GL_WCTYPE_H
  23. #if __GNUC__ >= 3
  24. @PRAGMA_SYSTEM_HEADER@
  25. #endif
  26. #if @HAVE_WINT_T@
  27. /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.
  28. Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  29. <wchar.h>.
  30. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  31. included before <wchar.h>. */
  32. # include <stddef.h>
  33. # include <stdio.h>
  34. # include <time.h>
  35. # include <wchar.h>
  36. #endif
  37. /* Include the original <wctype.h> if it exists.
  38. BeOS 5 has the functions but no <wctype.h>. */
  39. /* The include_next requires a split double-inclusion guard. */
  40. #if @HAVE_WCTYPE_H@
  41. # @INCLUDE_NEXT@ @NEXT_WCTYPE_H@
  42. #endif
  43. #ifndef _GL_WCTYPE_H
  44. #define _GL_WCTYPE_H
  45. /* Define wint_t. (Also done in wchar.in.h.) */
  46. #if !@HAVE_WINT_T@ && !defined wint_t
  47. # define wint_t int
  48. # ifndef WEOF
  49. # define WEOF -1
  50. # endif
  51. #endif
  52. /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
  53. Linux libc5 has <wctype.h> and the functions but they are broken.
  54. Assume all 12 functions are implemented the same way, or not at all. */
  55. #if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
  56. /* IRIX 5.3 has macros but no functions, its isw* macros refer to an
  57. undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
  58. refer to system functions like _iswctype that are not in the
  59. standard C library. Rather than try to get ancient buggy
  60. implementations like this to work, just disable them. */
  61. # undef iswalnum
  62. # undef iswalpha
  63. # undef iswblank
  64. # undef iswcntrl
  65. # undef iswdigit
  66. # undef iswgraph
  67. # undef iswlower
  68. # undef iswprint
  69. # undef iswpunct
  70. # undef iswspace
  71. # undef iswupper
  72. # undef iswxdigit
  73. /* Linux libc5 has <wctype.h> and the functions but they are broken. */
  74. # if @REPLACE_ISWCNTRL@
  75. # define iswalnum rpl_iswalnum
  76. # define iswalpha rpl_iswalpha
  77. # define iswblank rpl_iswblank
  78. # define iswcntrl rpl_iswcntrl
  79. # define iswdigit rpl_iswdigit
  80. # define iswgraph rpl_iswgraph
  81. # define iswlower rpl_iswlower
  82. # define iswprint rpl_iswprint
  83. # define iswpunct rpl_iswpunct
  84. # define iswspace rpl_iswspace
  85. # define iswupper rpl_iswupper
  86. # define iswxdigit rpl_iswxdigit
  87. # endif
  88. static inline int
  89. iswalnum (wint_t wc)
  90. {
  91. return ((wc >= '0' && wc <= '9')
  92. || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
  93. }
  94. static inline int
  95. iswalpha (wint_t wc)
  96. {
  97. return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
  98. }
  99. static inline int
  100. iswblank (wint_t wc)
  101. {
  102. return wc == ' ' || wc == '\t';
  103. }
  104. static inline int
  105. iswcntrl (wint_t wc)
  106. {
  107. return (wc & ~0x1f) == 0 || wc == 0x7f;
  108. }
  109. static inline int
  110. iswdigit (wint_t wc)
  111. {
  112. return wc >= '0' && wc <= '9';
  113. }
  114. static inline int
  115. iswgraph (wint_t wc)
  116. {
  117. return wc >= '!' && wc <= '~';
  118. }
  119. static inline int
  120. iswlower (wint_t wc)
  121. {
  122. return wc >= 'a' && wc <= 'z';
  123. }
  124. static inline int
  125. iswprint (wint_t wc)
  126. {
  127. return wc >= ' ' && wc <= '~';
  128. }
  129. static inline int
  130. iswpunct (wint_t wc)
  131. {
  132. return (wc >= '!' && wc <= '~'
  133. && !((wc >= '0' && wc <= '9')
  134. || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
  135. }
  136. static inline int
  137. iswspace (wint_t wc)
  138. {
  139. return (wc == ' ' || wc == '\t'
  140. || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
  141. }
  142. static inline int
  143. iswupper (wint_t wc)
  144. {
  145. return wc >= 'A' && wc <= 'Z';
  146. }
  147. static inline int
  148. iswxdigit (wint_t wc)
  149. {
  150. return ((wc >= '0' && wc <= '9')
  151. || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
  152. }
  153. # endif /* ! HAVE_ISWCNTRL */
  154. #endif /* _GL_WCTYPE_H */
  155. #endif /* _GL_WCTYPE_H */