]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/config/locale/gnu/ctype_members.cc
1 // std::ctype implementation details, GNU version -*- C++ -*-
3 // Copyright (C) 2001, 2002 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
31 // ISO C++ 14882: 22.2.1.1.2 ctype virtual functions.
34 // Written by Benjamin Kosnik <bkoz@redhat.com>
37 #include "c++locale_internal.h"
41 // NB: The other ctype<char> specializations are in src/locale.cc and
42 // various /config/os/* files.
44 ctype_byname
<char>::ctype_byname(const char* __s
, size_t __refs
)
45 : ctype
<char>(0, false, __refs
)
47 _S_destroy_c_locale(_M_c_locale_ctype
);
48 _S_create_c_locale(_M_c_locale_ctype
, __s
);
49 _M_toupper
= _M_c_locale_ctype
->__ctype_toupper
;
50 _M_tolower
= _M_c_locale_ctype
->__ctype_tolower
;
51 _M_table
= _M_c_locale_ctype
->__ctype_b
;
54 #ifdef _GLIBCPP_USE_WCHAR_T
55 ctype
<wchar_t>::__wmask_type
56 ctype
<wchar_t>::_M_convert_to_wmask(const mask __m
) const
62 __ret
= __wctype_l("space", _M_c_locale_ctype
);
65 __ret
= __wctype_l("print", _M_c_locale_ctype
);
68 __ret
= __wctype_l("cntrl", _M_c_locale_ctype
);
71 __ret
= __wctype_l("upper", _M_c_locale_ctype
);
74 __ret
= __wctype_l("lower", _M_c_locale_ctype
);
77 __ret
= __wctype_l("alpha", _M_c_locale_ctype
);
80 __ret
= __wctype_l("digit", _M_c_locale_ctype
);
83 __ret
= __wctype_l("punct", _M_c_locale_ctype
);
86 __ret
= __wctype_l("xdigit", _M_c_locale_ctype
);
89 __ret
= __wctype_l("alnum", _M_c_locale_ctype
);
92 __ret
= __wctype_l("graph", _M_c_locale_ctype
);
101 ctype
<wchar_t>::do_toupper(wchar_t __c
) const
102 { return __towupper_l(__c
, _M_c_locale_ctype
); }
105 ctype
<wchar_t>::do_toupper(wchar_t* __lo
, const wchar_t* __hi
) const
109 *__lo
= __towupper_l(*__lo
, _M_c_locale_ctype
);
116 ctype
<wchar_t>::do_tolower(wchar_t __c
) const
117 { return __towlower_l(__c
, _M_c_locale_ctype
); }
120 ctype
<wchar_t>::do_tolower(wchar_t* __lo
, const wchar_t* __hi
) const
124 *__lo
= __towlower_l(*__lo
, _M_c_locale_ctype
);
132 do_is(mask __m
, char_type __c
) const
134 return static_cast<bool>(__iswctype_l(__c
, _M_convert_to_wmask(__m
),
140 do_is(const wchar_t* __lo
, const wchar_t* __hi
, mask
* __m
) const
142 while (__lo
< __hi
&& !this->do_is(*__m
, *__lo
))
149 do_scan_is(mask __m
, const wchar_t* __lo
, const wchar_t* __hi
) const
151 while (__lo
< __hi
&& !this->do_is(__m
, *__lo
))
158 do_scan_not(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const
160 while (__lo
< __hi
&& this->do_is(__m
, *__lo
) != 0)
167 do_widen(char __c
) const
169 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
170 __c_locale __old
= __uselocale(_M_c_locale_ctype
);
172 wchar_t __ret
= btowc(__c
);
173 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
181 do_widen(const char* __lo
, const char* __hi
, wchar_t* __dest
) const
183 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
184 __c_locale __old
= __uselocale(_M_c_locale_ctype
);
187 memset(static_cast<void*>(&__state
), 0, sizeof(mbstate_t));
188 mbsrtowcs(__dest
, &__lo
, __hi
- __lo
, &__state
);
189 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
197 do_narrow(wchar_t __wc
, char __dfault
) const
199 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
200 __c_locale __old
= __uselocale(_M_c_locale_ctype
);
202 int __c
= wctob(__wc
);
203 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
206 return (__c
== EOF
? __dfault
: static_cast<char>(__c
));
211 do_narrow(const wchar_t* __lo
, const wchar_t* __hi
, char __dfault
,
214 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
215 __c_locale __old
= __uselocale(_M_c_locale_ctype
);
220 const wchar_t* __start
= __lo
+ __offset
;
221 size_t __len
= __hi
- __start
;
224 memset(static_cast<void*>(&__state
), 0, sizeof(mbstate_t));
225 size_t __con
= wcsrtombs(__dest
+ __offset
, &__start
, __len
, &__state
);
226 if (__con
!= __len
&& __start
!= 0)
228 __offset
= __start
- __lo
;
229 __dest
[__offset
++] = __dfault
;
234 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
239 #endif // _GLIBCPP_USE_WCHAR_T