]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/config/locale/generic/ctype_members.cc
Makefile.in (OBJS-common): Add tree-ssa-alias-warnings.o.
[thirdparty/gcc.git] / libstdc++-v3 / config / locale / generic / ctype_members.cc
CommitLineData
def9790d
BK
1// std::ctype implementation details, generic version -*- C++ -*-
2
681a6919
PC
3// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
4// Free Software Foundation, Inc.
def9790d
BK
5//
6// This file is part of the GNU ISO C++ Library. This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 2, or (at your option)
10// any later version.
11
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16
17// You should have received a copy of the GNU General Public License along
18// with this library; see the file COPYING. If not, write to the Free
83f51799 19// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
def9790d
BK
20// USA.
21
22// As a special exception, you may use this file as part of a free software
23// library without restriction. Specifically, if other files instantiate
24// templates or use macros or inline functions from this file, or you compile
25// this file and link it with other files to produce an executable, this
26// file does not by itself cause the resulting executable to be covered by
27// the GNU General Public License. This exception does not however
28// invalidate any other reasons why the executable file might be covered by
29// the GNU General Public License.
30
31//
32// ISO C++ 14882: 22.2.1.1.2 ctype virtual functions.
33//
34
35// Written by Benjamin Kosnik <bkoz@redhat.com>
36
37#include <locale>
4ba851b5 38#include <cstdlib>
def9790d 39
3cbc7af0
BK
40_GLIBCXX_BEGIN_NAMESPACE(std)
41
def9790d
BK
42 // NB: The other ctype<char> specializations are in src/locale.cc and
43 // various /config/os/* files.
681a6919
PC
44 ctype_byname<char>::ctype_byname(const char* __s, size_t __refs)
45 : ctype<char>(0, false, __refs)
46 {
47 if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0)
48 {
49 this->_S_destroy_c_locale(this->_M_c_locale_ctype);
50 this->_S_create_c_locale(this->_M_c_locale_ctype, __s);
51 }
52 }
53
54 ctype_byname<char>::~ctype_byname()
55 { }
def9790d 56
3d7c150e 57#ifdef _GLIBCXX_USE_WCHAR_T
def9790d
BK
58 ctype<wchar_t>::__wmask_type
59 ctype<wchar_t>::_M_convert_to_wmask(const mask __m) const
60 {
61 __wmask_type __ret;
62 switch (__m)
63 {
64 case space:
65 __ret = wctype("space");
66 break;
67 case print:
68 __ret = wctype("print");
69 break;
70 case cntrl:
71 __ret = wctype("cntrl");
72 break;
73 case upper:
74 __ret = wctype("upper");
75 break;
76 case lower:
77 __ret = wctype("lower");
78 break;
79 case alpha:
80 __ret = wctype("alpha");
81 break;
82 case digit:
83 __ret = wctype("digit");
84 break;
85 case punct:
86 __ret = wctype("punct");
87 break;
88 case xdigit:
89 __ret = wctype("xdigit");
90 break;
91 case alnum:
92 __ret = wctype("alnum");
93 break;
94 case graph:
95 __ret = wctype("graph");
96 break;
97 default:
03a2b810 98 __ret = __wmask_type();
def9790d
BK
99 }
100 return __ret;
101 };
102
103 wchar_t
104 ctype<wchar_t>::do_toupper(wchar_t __c) const
105 { return towupper(__c); }
106
107 const wchar_t*
108 ctype<wchar_t>::do_toupper(wchar_t* __lo, const wchar_t* __hi) const
109 {
110 while (__lo < __hi)
111 {
112 *__lo = towupper(*__lo);
113 ++__lo;
114 }
115 return __hi;
116 }
117
118 wchar_t
119 ctype<wchar_t>::do_tolower(wchar_t __c) const
120 { return towlower(__c); }
121
122 const wchar_t*
123 ctype<wchar_t>::do_tolower(wchar_t* __lo, const wchar_t* __hi) const
124 {
125 while (__lo < __hi)
126 {
127 *__lo = towlower(*__lo);
128 ++__lo;
129 }
130 return __hi;
131 }
132
133 bool
134 ctype<wchar_t>::
135 do_is(mask __m, char_type __c) const
465ad0c7 136 {
ba9b12d1 137 bool __ret = false;
2f800bcc
PC
138 // Generically, 15 (instead of 10) since we don't know the numerical
139 // encoding of the various categories in /usr/include/ctype.h.
140 const size_t __bitmasksize = 15;
465ad0c7 141 for (size_t __bitcur = 0; __bitcur <= __bitmasksize; ++__bitcur)
9a1349b9
PC
142 if (__m & _M_bit[__bitcur]
143 && iswctype(__c, _M_wmask[__bitcur]))
144 {
145 __ret = true;
146 break;
147 }
ba9b12d1 148 return __ret;
465ad0c7 149 }
def9790d
BK
150
151 const wchar_t*
152 ctype<wchar_t>::
465ad0c7 153 do_is(const wchar_t* __lo, const wchar_t* __hi, mask* __vec) const
def9790d 154 {
465ad0c7
BK
155 for (;__lo < __hi; ++__vec, ++__lo)
156 {
2f800bcc
PC
157 // Generically, 15 (instead of 10) since we don't know the numerical
158 // encoding of the various categories in /usr/include/ctype.h.
159 const size_t __bitmasksize = 15;
465ad0c7
BK
160 mask __m = 0;
161 for (size_t __bitcur = 0; __bitcur <= __bitmasksize; ++__bitcur)
9a1349b9
PC
162 if (iswctype(*__lo, _M_wmask[__bitcur]))
163 __m |= _M_bit[__bitcur];
465ad0c7
BK
164 *__vec = __m;
165 }
166 return __hi;
def9790d
BK
167 }
168
169 const wchar_t*
170 ctype<wchar_t>::
171 do_scan_is(mask __m, const wchar_t* __lo, const wchar_t* __hi) const
172 {
173 while (__lo < __hi && !this->do_is(__m, *__lo))
174 ++__lo;
175 return __lo;
176 }
177
178 const wchar_t*
179 ctype<wchar_t>::
180 do_scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
181 {
182 while (__lo < __hi && this->do_is(__m, *__lo) != 0)
183 ++__lo;
184 return __lo;
185 }
186
187 wchar_t
188 ctype<wchar_t>::
189 do_widen(char __c) const
ca13fb7f 190 { return _M_widen[static_cast<unsigned char>(__c)]; }
def9790d
BK
191
192 const char*
193 ctype<wchar_t>::
194 do_widen(const char* __lo, const char* __hi, wchar_t* __dest) const
195 {
ac1613a2
BK
196 while (__lo < __hi)
197 {
ca13fb7f 198 *__dest = _M_widen[static_cast<unsigned char>(*__lo)];
ac1613a2
BK
199 ++__lo;
200 ++__dest;
201 }
def9790d
BK
202 return __hi;
203 }
204
205 char
206 ctype<wchar_t>::
207 do_narrow(wchar_t __wc, char __dfault) const
208 {
e3c0c098
PC
209 if (__wc >= 0 && __wc < 128 && _M_narrow_ok)
210 return _M_narrow[__wc];
211 const int __c = wctob(__wc);
def9790d
BK
212 return (__c == EOF ? __dfault : static_cast<char>(__c));
213 }
214
215 const wchar_t*
216 ctype<wchar_t>::
217 do_narrow(const wchar_t* __lo, const wchar_t* __hi, char __dfault,
218 char* __dest) const
219 {
e3c0c098
PC
220 if (_M_narrow_ok)
221 while (__lo < __hi)
222 {
223 if (*__lo >= 0 && *__lo < 128)
224 *__dest = _M_narrow[*__lo];
225 else
226 {
227 const int __c = wctob(*__lo);
228 *__dest = (__c == EOF ? __dfault : static_cast<char>(__c));
229 }
230 ++__lo;
231 ++__dest;
232 }
233 else
234 while (__lo < __hi)
235 {
236 const int __c = wctob(*__lo);
237 *__dest = (__c == EOF ? __dfault : static_cast<char>(__c));
238 ++__lo;
239 ++__dest;
240 }
241 return __hi;
242 }
243
244 void
245 ctype<wchar_t>::_M_initialize_ctype()
246 {
247 wint_t __i;
248 for (__i = 0; __i < 128; ++__i)
f64ce6c6 249 {
e3c0c098
PC
250 const int __c = wctob(__i);
251 if (__c == EOF)
252 break;
253 else
254 _M_narrow[__i] = static_cast<char>(__c);
f64ce6c6 255 }
e3c0c098
PC
256 if (__i == 128)
257 _M_narrow_ok = true;
258 else
259 _M_narrow_ok = false;
ca13fb7f
PC
260 for (size_t __i = 0;
261 __i < sizeof(_M_widen) / sizeof(wint_t); ++__i)
e3c0c098 262 _M_widen[__i] = btowc(__i);
9a1349b9
PC
263
264 for (size_t __i = 0; __i <= 15; ++__i)
265 {
266 _M_bit[__i] = static_cast<mask>(1 << __i);
267 _M_wmask[__i] = _M_convert_to_wmask(_M_bit[__i]);
268 }
def9790d 269 }
3d7c150e 270#endif // _GLIBCXX_USE_WCHAR_T
3cbc7af0
BK
271
272_GLIBCXX_END_NAMESPACE