Update.
[glibc.git] / wctype / wcfuncs_l.c
blob5ef543cc47b33c0f02859ee4fc784c2960742a3c
1 /* Copyright (C) 1996, 1997, 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 <stdint.h>
23 #define USE_IN_EXTENDED_LOCALE_MODEL
24 #include "cname-lookup.h"
25 #include "wchar-lookup.h"
27 /* Provide real-function versions of all the wctype macros. */
29 #define func(name, type) \
30 int name (wint_t wc, __locale_t locale) \
31 { \
32 if (locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_HASH_SIZE)].word != 0) \
33 { \
34 /* Old locale format. */ \
35 const uint32_t *class32_b; \
36 size_t idx; \
38 idx = cname_lookup (wc, locale); \
39 if (idx == ~((size_t) 0)) \
40 return 0; \
42 class32_b = (uint32_t *) \
43 locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_CLASS32)].string; \
45 return class32_b[idx] & _ISwbit (type); \
46 } \
47 else \
48 { \
49 /* New locale format. */ \
50 size_t i = locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_CLASS_OFFSET)].word + type; \
51 const char *desc = locale->__locales[LC_CTYPE]->values[i].string; \
52 return wctype_table_lookup (desc, wc); \
53 } \
56 func (__iswalnum_l, __ISwalnum)
57 func (__iswalpha_l, __ISwalpha)
58 func (__iswcntrl_l, __ISwcntrl)
59 func (__iswdigit_l, __ISwdigit)
60 func (__iswlower_l, __ISwlower)
61 func (__iswgraph_l, __ISwgraph)
62 func (__iswprint_l, __ISwprint)
63 func (__iswpunct_l, __ISwpunct)
64 func (__iswspace_l, __ISwspace)
65 func (__iswupper_l, __ISwupper)
66 func (__iswxdigit_l, __ISwxdigit)
68 wint_t
69 (__towlower_l) (wint_t wc, __locale_t locale)
71 if (locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_HASH_SIZE)].word != 0)
73 /* Old locale format. */
74 const int32_t *class32_tolower;
75 size_t idx;
77 idx = cname_lookup (wc, locale);
78 if (idx == ~((size_t) 0))
79 return 0;
81 class32_tolower = (const int32_t *)
82 locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_TOLOWER32)].string;
84 return class32_tolower[idx];
86 else
88 /* New locale format. */
89 size_t i = locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_MAP_OFFSET)].word + __TOW_tolower;
90 const char *desc = locale->__locales[LC_CTYPE]->values[i].string;
91 return wctrans_table_lookup (desc, wc);
95 wint_t
96 (__towupper_l) (wint_t wc, __locale_t locale)
98 if (locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_HASH_SIZE)].word != 0)
100 /* Old locale format. */
101 const int32_t *class32_toupper;
102 size_t idx;
104 idx = cname_lookup (wc, locale);
105 if (idx == ~((size_t) 0))
106 return 0;
108 class32_toupper = (const int32_t *)
109 locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_TOUPPER32)].string;
111 return class32_toupper[idx];
113 else
115 /* New locale format. */
116 size_t i = locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_MAP_OFFSET)].word + __TOW_toupper;
117 const char *desc = locale->__locales[LC_CTYPE]->values[i].string;
118 return wctrans_table_lookup (desc, wc);