wctype.in.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. /* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
  2. Copyright (C) 2006-2013 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 Lesser General Public License as published by
  5. the Free Software Foundation; either version 2, 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 Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, see <http://www.gnu.org/licenses/>. */
  13. /* Written by Bruno Haible and Paul Eggert. */
  14. /*
  15. * ISO C 99 <wctype.h> for platforms that lack it.
  16. * <http://www.opengroup.org/susv3xbd/wctype.h.html>
  17. *
  18. * iswctype, towctrans, towlower, towupper, wctrans, wctype,
  19. * wctrans_t, and wctype_t are not yet implemented.
  20. */
  21. #ifndef _@GUARD_PREFIX@_WCTYPE_H
  22. #if __GNUC__ >= 3
  23. @PRAGMA_SYSTEM_HEADER@
  24. #endif
  25. @PRAGMA_COLUMNS@
  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 _@GUARD_PREFIX@_WCTYPE_H
  44. #define _@GUARD_PREFIX@_WCTYPE_H
  45. _GL_INLINE_HEADER_BEGIN
  46. #ifndef _GL_WCTYPE_INLINE
  47. # define _GL_WCTYPE_INLINE _GL_INLINE
  48. #endif
  49. /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
  50. /* The definition of _GL_WARN_ON_USE is copied here. */
  51. /* Solaris 2.6 <wctype.h> includes <widec.h> which includes <euc.h> which
  52. #defines a number of identifiers in the application namespace. Revert
  53. these #defines. */
  54. #ifdef __sun
  55. # undef multibyte
  56. # undef eucw1
  57. # undef eucw2
  58. # undef eucw3
  59. # undef scrw1
  60. # undef scrw2
  61. # undef scrw3
  62. #endif
  63. /* Define wint_t and WEOF. (Also done in wchar.in.h.) */
  64. #if !@HAVE_WINT_T@ && !defined wint_t
  65. # define wint_t int
  66. # ifndef WEOF
  67. # define WEOF -1
  68. # endif
  69. #else
  70. /* MSVC defines wint_t as 'unsigned short' in <crtdefs.h>.
  71. This is too small: ISO C 99 section 7.24.1.(2) says that wint_t must be
  72. "unchanged by default argument promotions". Override it. */
  73. # if defined _MSC_VER
  74. # if !GNULIB_defined_wint_t
  75. # include <crtdefs.h>
  76. typedef unsigned int rpl_wint_t;
  77. # undef wint_t
  78. # define wint_t rpl_wint_t
  79. # define GNULIB_defined_wint_t 1
  80. # endif
  81. # endif
  82. # ifndef WEOF
  83. # define WEOF ((wint_t) -1)
  84. # endif
  85. #endif
  86. #if !GNULIB_defined_wctype_functions
  87. /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
  88. Linux libc5 has <wctype.h> and the functions but they are broken.
  89. Assume all 11 functions (all isw* except iswblank) are implemented the
  90. same way, or not at all. */
  91. # if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
  92. /* IRIX 5.3 has macros but no functions, its isw* macros refer to an
  93. undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
  94. refer to system functions like _iswctype that are not in the
  95. standard C library. Rather than try to get ancient buggy
  96. implementations like this to work, just disable them. */
  97. # undef iswalnum
  98. # undef iswalpha
  99. # undef iswblank
  100. # undef iswcntrl
  101. # undef iswdigit
  102. # undef iswgraph
  103. # undef iswlower
  104. # undef iswprint
  105. # undef iswpunct
  106. # undef iswspace
  107. # undef iswupper
  108. # undef iswxdigit
  109. # undef towlower
  110. # undef towupper
  111. /* Linux libc5 has <wctype.h> and the functions but they are broken. */
  112. # if @REPLACE_ISWCNTRL@
  113. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  114. # define iswalnum rpl_iswalnum
  115. # define iswalpha rpl_iswalpha
  116. # define iswblank rpl_iswblank
  117. # define iswcntrl rpl_iswcntrl
  118. # define iswdigit rpl_iswdigit
  119. # define iswgraph rpl_iswgraph
  120. # define iswlower rpl_iswlower
  121. # define iswprint rpl_iswprint
  122. # define iswpunct rpl_iswpunct
  123. # define iswspace rpl_iswspace
  124. # define iswupper rpl_iswupper
  125. # define iswxdigit rpl_iswxdigit
  126. # endif
  127. # endif
  128. # if @REPLACE_TOWLOWER@
  129. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  130. # define towlower rpl_towlower
  131. # define towupper rpl_towupper
  132. # endif
  133. # endif
  134. _GL_WCTYPE_INLINE int
  135. # if @REPLACE_ISWCNTRL@
  136. rpl_iswalnum
  137. # else
  138. iswalnum
  139. # endif
  140. (wint_t wc)
  141. {
  142. return ((wc >= '0' && wc <= '9')
  143. || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
  144. }
  145. _GL_WCTYPE_INLINE int
  146. # if @REPLACE_ISWCNTRL@
  147. rpl_iswalpha
  148. # else
  149. iswalpha
  150. # endif
  151. (wint_t wc)
  152. {
  153. return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
  154. }
  155. _GL_WCTYPE_INLINE int
  156. # if @REPLACE_ISWCNTRL@
  157. rpl_iswblank
  158. # else
  159. iswblank
  160. # endif
  161. (wint_t wc)
  162. {
  163. return wc == ' ' || wc == '\t';
  164. }
  165. _GL_WCTYPE_INLINE int
  166. # if @REPLACE_ISWCNTRL@
  167. rpl_iswcntrl
  168. # else
  169. iswcntrl
  170. # endif
  171. (wint_t wc)
  172. {
  173. return (wc & ~0x1f) == 0 || wc == 0x7f;
  174. }
  175. _GL_WCTYPE_INLINE int
  176. # if @REPLACE_ISWCNTRL@
  177. rpl_iswdigit
  178. # else
  179. iswdigit
  180. # endif
  181. (wint_t wc)
  182. {
  183. return wc >= '0' && wc <= '9';
  184. }
  185. _GL_WCTYPE_INLINE int
  186. # if @REPLACE_ISWCNTRL@
  187. rpl_iswgraph
  188. # else
  189. iswgraph
  190. # endif
  191. (wint_t wc)
  192. {
  193. return wc >= '!' && wc <= '~';
  194. }
  195. _GL_WCTYPE_INLINE int
  196. # if @REPLACE_ISWCNTRL@
  197. rpl_iswlower
  198. # else
  199. iswlower
  200. # endif
  201. (wint_t wc)
  202. {
  203. return wc >= 'a' && wc <= 'z';
  204. }
  205. _GL_WCTYPE_INLINE int
  206. # if @REPLACE_ISWCNTRL@
  207. rpl_iswprint
  208. # else
  209. iswprint
  210. # endif
  211. (wint_t wc)
  212. {
  213. return wc >= ' ' && wc <= '~';
  214. }
  215. _GL_WCTYPE_INLINE int
  216. # if @REPLACE_ISWCNTRL@
  217. rpl_iswpunct
  218. # else
  219. iswpunct
  220. # endif
  221. (wint_t wc)
  222. {
  223. return (wc >= '!' && wc <= '~'
  224. && !((wc >= '0' && wc <= '9')
  225. || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
  226. }
  227. _GL_WCTYPE_INLINE int
  228. # if @REPLACE_ISWCNTRL@
  229. rpl_iswspace
  230. # else
  231. iswspace
  232. # endif
  233. (wint_t wc)
  234. {
  235. return (wc == ' ' || wc == '\t'
  236. || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
  237. }
  238. _GL_WCTYPE_INLINE int
  239. # if @REPLACE_ISWCNTRL@
  240. rpl_iswupper
  241. # else
  242. iswupper
  243. # endif
  244. (wint_t wc)
  245. {
  246. return wc >= 'A' && wc <= 'Z';
  247. }
  248. _GL_WCTYPE_INLINE int
  249. # if @REPLACE_ISWCNTRL@
  250. rpl_iswxdigit
  251. # else
  252. iswxdigit
  253. # endif
  254. (wint_t wc)
  255. {
  256. return ((wc >= '0' && wc <= '9')
  257. || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
  258. }
  259. _GL_WCTYPE_INLINE wint_t
  260. # if @REPLACE_TOWLOWER@
  261. rpl_towlower
  262. # else
  263. towlower
  264. # endif
  265. (wint_t wc)
  266. {
  267. return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc);
  268. }
  269. _GL_WCTYPE_INLINE wint_t
  270. # if @REPLACE_TOWLOWER@
  271. rpl_towupper
  272. # else
  273. towupper
  274. # endif
  275. (wint_t wc)
  276. {
  277. return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc);
  278. }
  279. # elif @GNULIB_ISWBLANK@ && (! @HAVE_ISWBLANK@ || @REPLACE_ISWBLANK@)
  280. /* Only the iswblank function is missing. */
  281. # if @REPLACE_ISWBLANK@
  282. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  283. # define iswblank rpl_iswblank
  284. # endif
  285. _GL_FUNCDECL_RPL (iswblank, int, (wint_t wc));
  286. # else
  287. _GL_FUNCDECL_SYS (iswblank, int, (wint_t wc));
  288. # endif
  289. # endif
  290. # if defined __MINGW32__
  291. /* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t.
  292. The functions towlower and towupper are implemented in the MSVCRT library
  293. to take a wchar_t argument and return a wchar_t result. mingw declares
  294. these functions to take a wint_t argument and return a wint_t result.
  295. This means that:
  296. 1. When the user passes an argument outside the range 0x0000..0xFFFF, the
  297. function will look only at the lower 16 bits. This is allowed according
  298. to POSIX.
  299. 2. The return value is returned in the lower 16 bits of the result register.
  300. The upper 16 bits are random: whatever happened to be in that part of the
  301. result register. We need to fix this by adding a zero-extend from
  302. wchar_t to wint_t after the call. */
  303. _GL_WCTYPE_INLINE wint_t
  304. rpl_towlower (wint_t wc)
  305. {
  306. return (wint_t) (wchar_t) towlower (wc);
  307. }
  308. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  309. # define towlower rpl_towlower
  310. # endif
  311. _GL_WCTYPE_INLINE wint_t
  312. rpl_towupper (wint_t wc)
  313. {
  314. return (wint_t) (wchar_t) towupper (wc);
  315. }
  316. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  317. # define towupper rpl_towupper
  318. # endif
  319. # endif /* __MINGW32__ */
  320. # define GNULIB_defined_wctype_functions 1
  321. #endif
  322. #if @REPLACE_ISWCNTRL@
  323. _GL_CXXALIAS_RPL (iswalnum, int, (wint_t wc));
  324. _GL_CXXALIAS_RPL (iswalpha, int, (wint_t wc));
  325. _GL_CXXALIAS_RPL (iswcntrl, int, (wint_t wc));
  326. _GL_CXXALIAS_RPL (iswdigit, int, (wint_t wc));
  327. _GL_CXXALIAS_RPL (iswgraph, int, (wint_t wc));
  328. _GL_CXXALIAS_RPL (iswlower, int, (wint_t wc));
  329. _GL_CXXALIAS_RPL (iswprint, int, (wint_t wc));
  330. _GL_CXXALIAS_RPL (iswpunct, int, (wint_t wc));
  331. _GL_CXXALIAS_RPL (iswspace, int, (wint_t wc));
  332. _GL_CXXALIAS_RPL (iswupper, int, (wint_t wc));
  333. _GL_CXXALIAS_RPL (iswxdigit, int, (wint_t wc));
  334. #else
  335. _GL_CXXALIAS_SYS (iswalnum, int, (wint_t wc));
  336. _GL_CXXALIAS_SYS (iswalpha, int, (wint_t wc));
  337. _GL_CXXALIAS_SYS (iswcntrl, int, (wint_t wc));
  338. _GL_CXXALIAS_SYS (iswdigit, int, (wint_t wc));
  339. _GL_CXXALIAS_SYS (iswgraph, int, (wint_t wc));
  340. _GL_CXXALIAS_SYS (iswlower, int, (wint_t wc));
  341. _GL_CXXALIAS_SYS (iswprint, int, (wint_t wc));
  342. _GL_CXXALIAS_SYS (iswpunct, int, (wint_t wc));
  343. _GL_CXXALIAS_SYS (iswspace, int, (wint_t wc));
  344. _GL_CXXALIAS_SYS (iswupper, int, (wint_t wc));
  345. _GL_CXXALIAS_SYS (iswxdigit, int, (wint_t wc));
  346. #endif
  347. _GL_CXXALIASWARN (iswalnum);
  348. _GL_CXXALIASWARN (iswalpha);
  349. _GL_CXXALIASWARN (iswcntrl);
  350. _GL_CXXALIASWARN (iswdigit);
  351. _GL_CXXALIASWARN (iswgraph);
  352. _GL_CXXALIASWARN (iswlower);
  353. _GL_CXXALIASWARN (iswprint);
  354. _GL_CXXALIASWARN (iswpunct);
  355. _GL_CXXALIASWARN (iswspace);
  356. _GL_CXXALIASWARN (iswupper);
  357. _GL_CXXALIASWARN (iswxdigit);
  358. #if @GNULIB_ISWBLANK@
  359. # if @REPLACE_ISWCNTRL@ || @REPLACE_ISWBLANK@
  360. _GL_CXXALIAS_RPL (iswblank, int, (wint_t wc));
  361. # else
  362. _GL_CXXALIAS_SYS (iswblank, int, (wint_t wc));
  363. # endif
  364. _GL_CXXALIASWARN (iswblank);
  365. #endif
  366. #if !@HAVE_WCTYPE_T@
  367. # if !GNULIB_defined_wctype_t
  368. typedef void * wctype_t;
  369. # define GNULIB_defined_wctype_t 1
  370. # endif
  371. #endif
  372. /* Get a descriptor for a wide character property. */
  373. #if @GNULIB_WCTYPE@
  374. # if !@HAVE_WCTYPE_T@
  375. _GL_FUNCDECL_SYS (wctype, wctype_t, (const char *name));
  376. # endif
  377. _GL_CXXALIAS_SYS (wctype, wctype_t, (const char *name));
  378. _GL_CXXALIASWARN (wctype);
  379. #elif defined GNULIB_POSIXCHECK
  380. # undef wctype
  381. # if HAVE_RAW_DECL_WCTYPE
  382. _GL_WARN_ON_USE (wctype, "wctype is unportable - "
  383. "use gnulib module wctype for portability");
  384. # endif
  385. #endif
  386. /* Test whether a wide character has a given property.
  387. The argument WC must be either a wchar_t value or WEOF.
  388. The argument DESC must have been returned by the wctype() function. */
  389. #if @GNULIB_ISWCTYPE@
  390. # if !@HAVE_WCTYPE_T@
  391. _GL_FUNCDECL_SYS (iswctype, int, (wint_t wc, wctype_t desc));
  392. # endif
  393. _GL_CXXALIAS_SYS (iswctype, int, (wint_t wc, wctype_t desc));
  394. _GL_CXXALIASWARN (iswctype);
  395. #elif defined GNULIB_POSIXCHECK
  396. # undef iswctype
  397. # if HAVE_RAW_DECL_ISWCTYPE
  398. _GL_WARN_ON_USE (iswctype, "iswctype is unportable - "
  399. "use gnulib module iswctype for portability");
  400. # endif
  401. #endif
  402. #if @REPLACE_TOWLOWER@ || defined __MINGW32__
  403. _GL_CXXALIAS_RPL (towlower, wint_t, (wint_t wc));
  404. _GL_CXXALIAS_RPL (towupper, wint_t, (wint_t wc));
  405. #else
  406. _GL_CXXALIAS_SYS (towlower, wint_t, (wint_t wc));
  407. _GL_CXXALIAS_SYS (towupper, wint_t, (wint_t wc));
  408. #endif
  409. _GL_CXXALIASWARN (towlower);
  410. _GL_CXXALIASWARN (towupper);
  411. #if !@HAVE_WCTRANS_T@
  412. # if !GNULIB_defined_wctrans_t
  413. typedef void * wctrans_t;
  414. # define GNULIB_defined_wctrans_t 1
  415. # endif
  416. #endif
  417. /* Get a descriptor for a wide character case conversion. */
  418. #if @GNULIB_WCTRANS@
  419. # if !@HAVE_WCTRANS_T@
  420. _GL_FUNCDECL_SYS (wctrans, wctrans_t, (const char *name));
  421. # endif
  422. _GL_CXXALIAS_SYS (wctrans, wctrans_t, (const char *name));
  423. _GL_CXXALIASWARN (wctrans);
  424. #elif defined GNULIB_POSIXCHECK
  425. # undef wctrans
  426. # if HAVE_RAW_DECL_WCTRANS
  427. _GL_WARN_ON_USE (wctrans, "wctrans is unportable - "
  428. "use gnulib module wctrans for portability");
  429. # endif
  430. #endif
  431. /* Perform a given case conversion on a wide character.
  432. The argument WC must be either a wchar_t value or WEOF.
  433. The argument DESC must have been returned by the wctrans() function. */
  434. #if @GNULIB_TOWCTRANS@
  435. # if !@HAVE_WCTRANS_T@
  436. _GL_FUNCDECL_SYS (towctrans, wint_t, (wint_t wc, wctrans_t desc));
  437. # endif
  438. _GL_CXXALIAS_SYS (towctrans, wint_t, (wint_t wc, wctrans_t desc));
  439. _GL_CXXALIASWARN (towctrans);
  440. #elif defined GNULIB_POSIXCHECK
  441. # undef towctrans
  442. # if HAVE_RAW_DECL_TOWCTRANS
  443. _GL_WARN_ON_USE (towctrans, "towctrans is unportable - "
  444. "use gnulib module towctrans for portability");
  445. # endif
  446. #endif
  447. _GL_INLINE_HEADER_END
  448. #endif /* _@GUARD_PREFIX@_WCTYPE_H */
  449. #endif /* _@GUARD_PREFIX@_WCTYPE_H */