ctype_noninline.h

Go to the documentation of this file.
00001 // Locale support -*- C++ -*-
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
00004 // 2006, 2007
00005 // Free Software Foundation, Inc.
00006 //
00007 // This file is part of the GNU ISO C++ Library.  This library is free
00008 // software; you can redistribute it and/or modify it under the
00009 // terms of the GNU General Public License as published by the
00010 // Free Software Foundation; either version 2, or (at your option)
00011 // any later version.
00012 
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 
00018 // You should have received a copy of the GNU General Public License along
00019 // with this library; see the file COPYING.  If not, write to the Free
00020 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00021 // USA.
00022 
00023 // As a special exception, you may use this file as part of a free software
00024 // library without restriction.  Specifically, if other files instantiate
00025 // templates or use macros or inline functions from this file, or you compile
00026 // this file and link it with other files to produce an executable, this
00027 // file does not by itself cause the resulting executable to be covered by
00028 // the GNU General Public License.  This exception does not however
00029 // invalidate any other reasons why the executable file might be covered by
00030 // the GNU General Public License.
00031 
00032 /** @file ctype_noninline.h
00033  *  This is an internal header file, included by other library headers.
00034  *  You should not attempt to use it directly.
00035  */
00036 
00037 //
00038 // ISO C++ 14882: 22.1  Locales
00039 //
00040   
00041 // Information as gleaned from /usr/include/ctype.h
00042 
00043 #if _GLIBCXX_C_LOCALE_GNU
00044   const ctype_base::mask*
00045   ctype<char>::classic_table() throw()
00046   { return _S_get_c_locale()->__ctype_b; }
00047 #else
00048   const ctype_base::mask*
00049   ctype<char>::classic_table() throw()
00050   {
00051     const ctype_base::mask* __ret;
00052     char* __old = setlocale(LC_CTYPE, NULL);
00053     char* __sav = NULL;
00054     if (__builtin_strcmp(__old, "C"))
00055       {
00056     const size_t __len = __builtin_strlen(__old) + 1;
00057     __sav = new char[__len];
00058     __builtin_memcpy(__sav, __old, __len);
00059     setlocale(LC_CTYPE, "C");
00060       }
00061 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
00062     __ret = *__ctype_b_loc();
00063 #else
00064     __ret = __ctype_b;
00065 #endif
00066     if (__sav)
00067       {
00068     setlocale(LC_CTYPE, __sav);
00069     delete [] __sav;
00070       }
00071     return __ret;
00072   }
00073 #endif
00074 
00075 #if _GLIBCXX_C_LOCALE_GNU
00076   ctype<char>::ctype(__c_locale __cloc, const mask* __table, bool __del, 
00077              size_t __refs) 
00078   : facet(__refs), _M_c_locale_ctype(_S_clone_c_locale(__cloc)), 
00079   _M_del(__table != 0 && __del), 
00080   _M_toupper(_M_c_locale_ctype->__ctype_toupper),  
00081   _M_tolower(_M_c_locale_ctype->__ctype_tolower), 
00082   _M_table(__table ? __table : _M_c_locale_ctype->__ctype_b), 
00083   _M_widen_ok(0), _M_narrow_ok(0) 
00084   {
00085     __builtin_memset(_M_widen, 0, sizeof(_M_widen));
00086     __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
00087   }
00088 #else
00089   ctype<char>::ctype(__c_locale, const mask* __table, bool __del, 
00090              size_t __refs) 
00091   : facet(__refs), _M_c_locale_ctype(_S_get_c_locale()), 
00092   _M_del(__table != 0 && __del), _M_widen_ok(0), _M_narrow_ok(0)
00093   {
00094     char* __old = setlocale(LC_CTYPE, NULL);
00095     char* __sav = NULL;
00096     if (__builtin_strcmp(__old, "C"))
00097       {    
00098     const size_t __len = __builtin_strlen(__old) + 1;
00099     __sav = new char[__len];
00100     __builtin_memcpy(__sav, __old, __len);    
00101     setlocale(LC_CTYPE, "C");
00102       }
00103 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
00104     _M_toupper = *__ctype_toupper_loc();
00105     _M_tolower = *__ctype_tolower_loc();
00106     _M_table = __table ? __table : *__ctype_b_loc();
00107 #else
00108     _M_toupper = __ctype_toupper;
00109     _M_tolower = __ctype_tolower;
00110     _M_table = __table ? __table : __ctype_b;
00111 #endif
00112     if (__sav)
00113       {
00114     setlocale(LC_CTYPE, __sav);
00115     delete [] __sav;
00116       }
00117     __builtin_memset(_M_widen, 0, sizeof(_M_widen));
00118     __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
00119   }
00120 #endif
00121 
00122 #if _GLIBCXX_C_LOCALE_GNU
00123   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs) 
00124   : facet(__refs), _M_c_locale_ctype(_S_get_c_locale()), 
00125   _M_del(__table != 0 && __del),
00126   _M_toupper(_M_c_locale_ctype->__ctype_toupper),  
00127   _M_tolower(_M_c_locale_ctype->__ctype_tolower), 
00128   _M_table(__table ? __table : _M_c_locale_ctype->__ctype_b), 
00129   _M_widen_ok(0), _M_narrow_ok(0) 
00130   {
00131     __builtin_memset(_M_widen, 0, sizeof(_M_widen));
00132     __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
00133   }
00134 #else
00135   ctype<char>::ctype(const mask* __table, bool __del, size_t __refs)
00136   : facet(__refs), _M_c_locale_ctype(_S_get_c_locale()), 
00137   _M_del(__table != 0 && __del), _M_widen_ok(0), _M_narrow_ok(0)
00138   {
00139     char* __old = setlocale(LC_CTYPE, NULL);
00140     char* __sav = NULL;
00141     if (__builtin_strcmp(__old, "C"))
00142       {
00143     const size_t __len = __builtin_strlen(__old) + 1;
00144     __sav = new char[__len];
00145     __builtin_memcpy(__sav, __old, __len);
00146     setlocale(LC_CTYPE, "C");
00147       }
00148 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
00149     _M_toupper = *__ctype_toupper_loc();
00150     _M_tolower = *__ctype_tolower_loc();
00151     _M_table = __table ? __table : *__ctype_b_loc();
00152 #else
00153     _M_toupper = __ctype_toupper;
00154     _M_tolower = __ctype_tolower;
00155     _M_table = __table ? __table : __ctype_b;
00156 #endif
00157     if (__sav)
00158       {
00159     setlocale(LC_CTYPE, __sav);
00160     delete [] __sav;
00161       }
00162     __builtin_memset(_M_widen, 0, sizeof(_M_widen));
00163     __builtin_memset(_M_narrow, 0, sizeof(_M_narrow));
00164   }
00165 #endif
00166 
00167   char
00168   ctype<char>::do_toupper(char __c) const
00169   { return _M_toupper[static_cast<unsigned char>(__c)]; }
00170 
00171   const char*
00172   ctype<char>::do_toupper(char* __low, const char* __high) const
00173   {
00174     while (__low < __high)
00175       {
00176     *__low = _M_toupper[static_cast<unsigned char>(*__low)];
00177     ++__low;
00178       }
00179     return __high;
00180   }
00181 
00182   char
00183   ctype<char>::do_tolower(char __c) const
00184   { return _M_tolower[static_cast<unsigned char>(__c)]; }
00185 
00186   const char* 
00187   ctype<char>::do_tolower(char* __low, const char* __high) const
00188   {
00189     while (__low < __high)
00190       {
00191     *__low = _M_tolower[static_cast<unsigned char>(*__low)];
00192     ++__low;
00193       }
00194     return __high;
00195   }

Generated on Sat Dec 12 09:40:09 2009 for libstdc++ by  doxygen 1.5.6