wctype.in.h 13 KB

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