wctype.in.h 13 KB

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