wctype.in.h 13 KB

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