wctype.in.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
  2. Copyright (C) 2006, 2007 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 @HAVE_WINT_T@
  24. /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.
  25. Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  26. <wchar.h>.
  27. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  28. included before <wchar.h>. */
  29. # include <stddef.h>
  30. # include <stdio.h>
  31. # include <time.h>
  32. # include <wchar.h>
  33. #endif
  34. /* Include the original <wctype.h> if it exists.
  35. BeOS 5 has the functions but no <wctype.h>. */
  36. /* The include_next requires a split double-inclusion guard. */
  37. #if @HAVE_WCTYPE_H@
  38. # @INCLUDE_NEXT@ @NEXT_WCTYPE_H@
  39. #endif
  40. #ifndef _GL_WCTYPE_H
  41. #define _GL_WCTYPE_H
  42. #if @HAVE_WINT_T@
  43. typedef wint_t __wctype_wint_t;
  44. #else
  45. typedef int __wctype_wint_t;
  46. #endif
  47. /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
  48. Assume all 12 functions are implemented the same way, or not at all. */
  49. #if ! @HAVE_ISWCNTRL@
  50. /* IRIX 5.3 has macros but no functions, its isw* macros refer to an
  51. undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
  52. refer to system functions like _iswctype that are not in the
  53. standard C library. Rather than try to get ancient buggy
  54. implementations like this to work, just disable them. */
  55. # undef iswalnum
  56. # undef iswalpha
  57. # undef iswblank
  58. # undef iswcntrl
  59. # undef iswdigit
  60. # undef iswgraph
  61. # undef iswlower
  62. # undef iswprint
  63. # undef iswpunct
  64. # undef iswspace
  65. # undef iswupper
  66. # undef iswxdigit
  67. static inline int
  68. iswalnum (__wctype_wint_t wc)
  69. {
  70. return ((wc >= '0' && wc <= '9')
  71. || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
  72. }
  73. static inline int
  74. iswalpha (__wctype_wint_t wc)
  75. {
  76. return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
  77. }
  78. static inline int
  79. iswblank (__wctype_wint_t wc)
  80. {
  81. return wc == ' ' || wc == '\t';
  82. }
  83. static inline int
  84. iswcntrl (__wctype_wint_t wc)
  85. {
  86. return (wc & ~0x1f) == 0 || wc == 0x7f;
  87. }
  88. static inline int
  89. iswdigit (__wctype_wint_t wc)
  90. {
  91. return wc >= '0' && wc <= '9';
  92. }
  93. static inline int
  94. iswgraph (__wctype_wint_t wc)
  95. {
  96. return wc >= '!' && wc <= '~';
  97. }
  98. static inline int
  99. iswlower (__wctype_wint_t wc)
  100. {
  101. return wc >= 'a' && wc <= 'z';
  102. }
  103. static inline int
  104. iswprint (__wctype_wint_t wc)
  105. {
  106. return wc >= ' ' && wc <= '~';
  107. }
  108. static inline int
  109. iswpunct (__wctype_wint_t wc)
  110. {
  111. return (wc >= '!' && wc <= '~'
  112. && !((wc >= '0' && wc <= '9')
  113. || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
  114. }
  115. static inline int
  116. iswspace (__wctype_wint_t wc)
  117. {
  118. return (wc == ' ' || wc == '\t'
  119. || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
  120. }
  121. static inline int
  122. iswupper (__wctype_wint_t wc)
  123. {
  124. return wc >= 'A' && wc <= 'Z';
  125. }
  126. static inline int
  127. iswxdigit (__wctype_wint_t wc)
  128. {
  129. return ((wc >= '0' && wc <= '9')
  130. || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
  131. }
  132. # endif /* ! HAVE_ISWCNTRL */
  133. #endif /* _GL_WCTYPE_H */
  134. #endif /* _GL_WCTYPE_H */