wctype.in.h 13 KB

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