]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/config/locale/generic/ctype_members.cc
1 // std::ctype implementation details, generic version -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 // Free Software Foundation, Inc.
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)
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.
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
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
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.
32 // ISO C++ 14882: 22.2.1.1.2 ctype virtual functions.
35 // Written by Benjamin Kosnik <bkoz@redhat.com>
42 _GLIBCXX_BEGIN_NAMESPACE(std
)
44 // NB: The other ctype<char> specializations are in src/locale.cc and
45 // various /config/os/* files.
46 ctype_byname
<char>::ctype_byname(const char* __s
, size_t __refs
)
47 : ctype
<char>(0, false, __refs
)
49 if (std::strcmp(__s
, "C") != 0 && std::strcmp(__s
, "POSIX") != 0)
51 this->_S_destroy_c_locale(this->_M_c_locale_ctype
);
52 this->_S_create_c_locale(this->_M_c_locale_ctype
, __s
);
56 ctype_byname
<char>::~ctype_byname()
59 #ifdef _GLIBCXX_USE_WCHAR_T
60 ctype
<wchar_t>::__wmask_type
61 ctype
<wchar_t>::_M_convert_to_wmask(const mask __m
) const
67 __ret
= wctype("space");
70 __ret
= wctype("print");
73 __ret
= wctype("cntrl");
76 __ret
= wctype("upper");
79 __ret
= wctype("lower");
82 __ret
= wctype("alpha");
85 __ret
= wctype("digit");
88 __ret
= wctype("punct");
91 __ret
= wctype("xdigit");
94 __ret
= wctype("alnum");
97 __ret
= wctype("graph");
100 __ret
= __wmask_type();
106 ctype
<wchar_t>::do_toupper(wchar_t __c
) const
107 { return towupper(__c
); }
110 ctype
<wchar_t>::do_toupper(wchar_t* __lo
, const wchar_t* __hi
) const
114 *__lo
= towupper(*__lo
);
121 ctype
<wchar_t>::do_tolower(wchar_t __c
) const
122 { return towlower(__c
); }
125 ctype
<wchar_t>::do_tolower(wchar_t* __lo
, const wchar_t* __hi
) const
129 *__lo
= towlower(*__lo
);
137 do_is(mask __m
, char_type __c
) const
140 // Generically, 15 (instead of 10) since we don't know the numerical
141 // encoding of the various categories in /usr/include/ctype.h.
142 const size_t __bitmasksize
= 15;
143 for (size_t __bitcur
= 0; __bitcur
<= __bitmasksize
; ++__bitcur
)
144 if (__m
& _M_bit
[__bitcur
]
145 && iswctype(__c
, _M_wmask
[__bitcur
]))
155 do_is(const wchar_t* __lo
, const wchar_t* __hi
, mask
* __vec
) const
157 for (;__lo
< __hi
; ++__vec
, ++__lo
)
159 // Generically, 15 (instead of 10) since we don't know the numerical
160 // encoding of the various categories in /usr/include/ctype.h.
161 const size_t __bitmasksize
= 15;
163 for (size_t __bitcur
= 0; __bitcur
<= __bitmasksize
; ++__bitcur
)
164 if (iswctype(*__lo
, _M_wmask
[__bitcur
]))
165 __m
|= _M_bit
[__bitcur
];
173 do_scan_is(mask __m
, const wchar_t* __lo
, const wchar_t* __hi
) const
175 while (__lo
< __hi
&& !this->do_is(__m
, *__lo
))
182 do_scan_not(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const
184 while (__lo
< __hi
&& this->do_is(__m
, *__lo
) != 0)
191 do_widen(char __c
) const
192 { return _M_widen
[static_cast<unsigned char>(__c
)]; }
196 do_widen(const char* __lo
, const char* __hi
, wchar_t* __dest
) const
200 *__dest
= _M_widen
[static_cast<unsigned char>(*__lo
)];
209 do_narrow(wchar_t __wc
, char __dfault
) const
211 if (__wc
>= 0 && __wc
< 128 && _M_narrow_ok
)
212 return _M_narrow
[__wc
];
213 const int __c
= wctob(__wc
);
214 return (__c
== EOF
? __dfault
: static_cast<char>(__c
));
219 do_narrow(const wchar_t* __lo
, const wchar_t* __hi
, char __dfault
,
225 if (*__lo
>= 0 && *__lo
< 128)
226 *__dest
= _M_narrow
[*__lo
];
229 const int __c
= wctob(*__lo
);
230 *__dest
= (__c
== EOF
? __dfault
: static_cast<char>(__c
));
238 const int __c
= wctob(*__lo
);
239 *__dest
= (__c
== EOF
? __dfault
: static_cast<char>(__c
));
247 ctype
<wchar_t>::_M_initialize_ctype()
250 for (__i
= 0; __i
< 128; ++__i
)
252 const int __c
= wctob(__i
);
256 _M_narrow
[__i
] = static_cast<char>(__c
);
261 _M_narrow_ok
= false;
263 __i
< sizeof(_M_widen
) / sizeof(wint_t); ++__i
)
264 _M_widen
[__i
] = btowc(__i
);
266 for (size_t __i
= 0; __i
<= 15; ++__i
)
268 _M_bit
[__i
] = static_cast<mask
>(1 << __i
);
269 _M_wmask
[__i
] = _M_convert_to_wmask(_M_bit
[__i
]);
272 #endif // _GLIBCXX_USE_WCHAR_T
274 _GLIBCXX_END_NAMESPACE