# ctype_noninline.h

Go to the documentation of this file.

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