ctype_noninline.h revision 117397
1// Locale support -*- C++ -*- 2 3// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 4// Free Software Foundation, Inc. 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 19// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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.1 Locales 33// 34 35// Information as gleaned from /usr/include/ctype.h 36 37#if _GLIBCPP_C_LOCALE_GNU 38 const ctype_base::mask* 39 ctype<char>::classic_table() throw() 40 { 41 locale::classic(); 42 return _S_c_locale->__ctype_b; 43 } 44#else 45 const ctype_base::mask* 46 ctype<char>::classic_table() throw() 47 { 48 const ctype_base::mask* __ret; 49 char* __old = strdup(setlocale(LC_CTYPE, NULL)); 50 setlocale(LC_CTYPE, "C"); 51#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) 52 __ret = *__ctype_b_loc(); 53#else 54 __ret = __ctype_b; 55#endif 56 setlocale(LC_CTYPE, __old); 57 free(__old); 58 return __ret; 59 } 60#endif 61 62#if _GLIBCPP_C_LOCALE_GNU 63 ctype<char>::ctype(__c_locale __cloc, const mask* __table, bool __del, 64 size_t __refs) 65 : __ctype_abstract_base<char>(__refs), _M_del(__table != 0 && __del) 66 { 67 _M_c_locale_ctype = _S_clone_c_locale(__cloc); 68 _M_toupper = _M_c_locale_ctype->__ctype_toupper; 69 _M_tolower = _M_c_locale_ctype->__ctype_tolower; 70 _M_table = __table ? __table : _M_c_locale_ctype->__ctype_b; 71 } 72#else 73 ctype<char>::ctype(__c_locale, const mask* __table, bool __del, 74 size_t __refs) 75 : __ctype_abstract_base<char>(__refs), _M_del(__table != 0 && __del) 76 { 77 char* __old=strdup(setlocale(LC_CTYPE, NULL)); 78 setlocale(LC_CTYPE, "C"); 79#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) 80 _M_toupper = *__ctype_toupper_loc(); 81 _M_tolower = *__ctype_tolower_loc(); 82 _M_table = __table ? __table : *__ctype_b_loc(); 83#else 84 _M_toupper = __ctype_toupper; 85 _M_tolower = __ctype_tolower; 86 _M_table = __table ? __table : __ctype_b; 87#endif 88 setlocale(LC_CTYPE, __old); 89 free(__old); 90 _M_c_locale_ctype = _S_c_locale; 91 } 92#endif 93 94#if _GLIBCPP_C_LOCALE_GNU 95 ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) : 96 __ctype_abstract_base<char>(__refs), _M_del(__table != 0 && __del) 97 { 98 _M_c_locale_ctype = _S_c_locale; 99 _M_toupper = _M_c_locale_ctype->__ctype_toupper; 100 _M_tolower = _M_c_locale_ctype->__ctype_tolower; 101 _M_table = __table ? __table : _M_c_locale_ctype->__ctype_b; 102 } 103#else 104 ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) : 105 __ctype_abstract_base<char>(__refs), _M_del(__table != 0 && __del) 106 { 107 char* __old=strdup(setlocale(LC_CTYPE, NULL)); 108 setlocale(LC_CTYPE, "C"); 109#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) 110 _M_toupper = *__ctype_toupper_loc(); 111 _M_tolower = *__ctype_tolower_loc(); 112 _M_table = __table ? __table : *__ctype_b_loc(); 113#else 114 _M_toupper = __ctype_toupper; 115 _M_tolower = __ctype_tolower; 116 _M_table = __table ? __table : __ctype_b; 117#endif 118 setlocale(LC_CTYPE, __old); 119 free(__old); 120 _M_c_locale_ctype = _S_c_locale; 121 } 122#endif 123 124 char 125 ctype<char>::do_toupper(char __c) const 126 { return _M_toupper[static_cast<unsigned char>(__c)]; } 127 128 const char* 129 ctype<char>::do_toupper(char* __low, const char* __high) const 130 { 131 while (__low < __high) 132 { 133 *__low = _M_toupper[static_cast<unsigned char>(*__low)]; 134 ++__low; 135 } 136 return __high; 137 } 138 139 char 140 ctype<char>::do_tolower(char __c) const 141 { return _M_tolower[static_cast<unsigned char>(__c)]; } 142 143 const char* 144 ctype<char>::do_tolower(char* __low, const char* __high) const 145 { 146 while (__low < __high) 147 { 148 *__low = _M_tolower[static_cast<unsigned char>(*__low)]; 149 ++__low; 150 } 151 return __high; 152 } 153