]> git.ipfire.org Git - thirdparty/glibc.git/blame - wctype/wcfuncs.c
Update.
[thirdparty/glibc.git] / wctype / wcfuncs.c
CommitLineData
b02b9253 1/* Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
c84142e8
UD
2 This file is part of the GNU C Library.
3
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.
8
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.
13
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. */
19bc17a9
RM
18
19#define __NO_WCTYPE
20#include <wctype.h>
21#include <ctype.h> /* For __ctype_tolower and __ctype_toupper. */
22
390955cb 23#include "cname-lookup.h"
ef446144 24#include "wchar-lookup.h"
390955cb 25
c96f6550
UD
26/* If the program is compiled without optimization the following declaration
27 is not visible in the header. */
28extern unsigned int *__ctype32_b;
b02b9253
UD
29
30/* These are not exported. */
49f2be5b
UD
31extern const uint32_t *__ctype32_toupper;
32extern const uint32_t *__ctype32_tolower;
ef446144
UD
33extern const char *__ctype32_wctype[12];
34extern const char *__ctype32_wctrans[2];
c96f6550 35
19bc17a9
RM
36/* Provide real-function versions of all the wctype macros. */
37
38#define func(name, type) \
390955cb
UD
39 int \
40 __##name (wint_t wc) \
41 { \
ef446144
UD
42 if (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_HASH_SIZE) != 0) \
43 { \
44 /* Old locale format. */ \
45 size_t idx; \
390955cb 46 \
ef446144
UD
47 idx = cname_lookup (wc); \
48 if (idx == ~((size_t) 0)) \
49 return 0; \
390955cb 50 \
ef446144
UD
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 } \
390955cb
UD
58 } \
59 weak_alias (__##name, name)
19bc17a9 60
390955cb 61#undef iswalnum
ef446144 62func (iswalnum, __ISwalnum)
390955cb 63#undef iswalpha
ef446144 64func (iswalpha, __ISwalpha)
390955cb 65#undef iswcntrl
ef446144 66func (iswcntrl, __ISwcntrl)
390955cb 67#undef iswdigit
ef446144 68func (iswdigit, __ISwdigit)
390955cb 69#undef iswlower
ef446144 70func (iswlower, __ISwlower)
390955cb 71#undef iswgraph
ef446144 72func (iswgraph, __ISwgraph)
390955cb 73#undef iswprint
ef446144 74func (iswprint, __ISwprint)
390955cb 75#undef iswpunct
ef446144 76func (iswpunct, __ISwpunct)
390955cb 77#undef iswspace
ef446144 78func (iswspace, __ISwspace)
390955cb 79#undef iswupper
ef446144 80func (iswupper, __ISwupper)
390955cb 81#undef iswxdigit
ef446144 82func (iswxdigit, __ISwxdigit)
19bc17a9
RM
83
84wint_t
390955cb 85(towlower) (wc)
19bc17a9
RM
86 wint_t wc;
87{
ef446144
UD
88 if (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_HASH_SIZE) != 0)
89 {
90 /* Old locale format. */
91 size_t idx;
92
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;
97
98 return (wint_t) __ctype32_tolower[idx];
99 }
100 else
101 {
102 /* New locale format. */
5e463393 103 return wctrans_table_lookup (__ctype32_wctrans[__TOW_tolower], wc);
ef446144 104 }
19bc17a9
RM
105}
106
107wint_t
390955cb 108(towupper) (wc)
19bc17a9
RM
109 wint_t wc;
110{
ef446144
UD
111 if (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_HASH_SIZE) != 0)
112 {
113 /* Old locale format. */
114 size_t idx;
115
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;
120
121 return (wint_t) __ctype32_toupper[idx];
122 }
123 else
124 {
125 /* New locale format. */
5e463393 126 return wctrans_table_lookup (__ctype32_wctrans[__TOW_toupper], wc);
ef446144 127 }
19bc17a9 128}