Update.
[glibc.git] / wctype / wcfuncs.c
blobea697c272972e151ae85e93d7171bbd7eea32deb
1 /* Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #define __NO_WCTYPE
20 #include <wctype.h>
21 #include <ctype.h> /* For __ctype_tolower and __ctype_toupper. */
23 #include "cname-lookup.h"
24 #include "wchar-lookup.h"
26 /* If the program is compiled without optimization the following declaration
27 is not visible in the header. */
28 extern unsigned int *__ctype32_b;
30 /* These are not exported. */
31 extern const uint32_t *__ctype32_toupper;
32 extern const uint32_t *__ctype32_tolower;
33 extern const char *__ctype32_wctype[12];
34 extern const char *__ctype32_wctrans[2];
36 /* Provide real-function versions of all the wctype macros. */
38 #define func(name, type) \
39 int \
40 __##name (wint_t wc) \
41 { \
42 if (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_HASH_SIZE) != 0) \
43 { \
44 /* Old locale format. */ \
45 size_t idx; \
47 idx = cname_lookup (wc); \
48 if (idx == ~((size_t) 0)) \
49 return 0; \
51 return __ctype32_b[idx] & _ISwbit (type); \
52 } \
53 else \
54 { \
55 /* New locale format. */ \
56 return wctype_table_lookup (__ctype32_wctype[type], wc); \
57 } \
58 } \
59 weak_alias (__##name, name)
61 #undef iswalnum
62 func (iswalnum, __ISwalnum)
63 #undef iswalpha
64 func (iswalpha, __ISwalpha)
65 #undef iswcntrl
66 func (iswcntrl, __ISwcntrl)
67 #undef iswdigit
68 func (iswdigit, __ISwdigit)
69 #undef iswlower
70 func (iswlower, __ISwlower)
71 #undef iswgraph
72 func (iswgraph, __ISwgraph)
73 #undef iswprint
74 func (iswprint, __ISwprint)
75 #undef iswpunct
76 func (iswpunct, __ISwpunct)
77 #undef iswspace
78 func (iswspace, __ISwspace)
79 #undef iswupper
80 func (iswupper, __ISwupper)
81 #undef iswxdigit
82 func (iswxdigit, __ISwxdigit)
84 wint_t
85 (towlower) (wc)
86 wint_t wc;
88 if (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_HASH_SIZE) != 0)
90 /* Old locale format. */
91 size_t idx;
93 idx = cname_lookup (wc);
94 if (idx == ~((size_t) 0))
95 /* Character is not known. Default action is to simply return it. */
96 return wc;
98 return (wint_t) __ctype32_tolower[idx];
100 else
102 /* New locale format. */
103 return wctrans_table_lookup (__ctype32_wctrans[__TOW_tolower], wc);
107 wint_t
108 (towupper) (wc)
109 wint_t wc;
111 if (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_HASH_SIZE) != 0)
113 /* Old locale format. */
114 size_t idx;
116 idx = cname_lookup (wc);
117 if (idx == ~((size_t) 0))
118 /* Character is not known. Default action is to simply return it. */
119 return wc;
121 return (wint_t) __ctype32_toupper[idx];
123 else
125 /* New locale format. */
126 return wctrans_table_lookup (__ctype32_wctrans[__TOW_toupper], wc);