# ctype.cc

    00001 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
    00002 // Free Software Foundation, Inc.
    00003 //
    00004 // This file is part of the GNU ISO C++ Library.  This library is free
    00005 // software; you can redistribute it and/or modify it under the
    00006 // terms of the GNU General Public License as published by the
    00007 // Free Software Foundation; either version 2, or (at your option)
    00008 // any later version.
    00009
    00010 // This library is distributed in the hope that it will be useful,
    00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00013 // GNU General Public License for more details.
    00014
    00015 // You should have received a copy of the GNU General Public License along
    00016 // with this library; see the file COPYING.  If not, write to the Free
    00017 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    00018 // USA.
    00019
    00020 // As a special exception, you may use this file as part of a free software
    00021 // library without restriction.  Specifically, if other files instantiate
    00022 // templates or use macros or inline functions from this file, or you compile
    00023 // this file and link it with other files to produce an executable, this
    00024 // file does not by itself cause the resulting executable to be covered by
    00025 // the GNU General Public License.  This exception does not however
    00026 // invalidate any other reasons why the executable file might be covered by
    00027 // the GNU General Public License.
    00028
    00029 #include <locale>
    00030
    00031 namespace std
    00032 {
    00033   // XXX At some point, just rename this file to ctype_members_char.cc
    00034   // and compile it as a separate file instead of including it here.
    00035   // Platform-specific initialization code for ctype tables.
    00036   #include <bits/ctype_noninline.h>
    00037
    00038   // Definitions for locale::id of standard facets that are specialized.
    00039   locale::id ctype<char>::id;
    00040
    00041 #ifdef _GLIBCPP_USE_WCHAR_T
    00042   locale::id ctype<wchar_t>::id;
    00043 #endif
    00044
    00045   template<>
    00046     const ctype<char>&
    00047     use_facet<ctype<char> >(const locale& __loc)
    00048     {
    00049       size_t __i = ctype<char>::id._M_id();
    00050       const locale::_Impl* __tmp = __loc._M_impl;
    00051       return static_cast<const ctype<char>&>(*(__tmp->_M_facets[__i]));
    00052     }
    00053
    00054 #ifdef _GLIBCPP_USE_WCHAR_T
    00055   template<>
    00056     const ctype<wchar_t>&
    00057     use_facet<ctype<wchar_t> >(const locale& __loc)
    00058     {
    00059       size_t __i = ctype<wchar_t>::id._M_id();
    00060       const locale::_Impl* __tmp = __loc._M_impl;
    00061       return static_cast<const ctype<wchar_t>&>(*(__tmp->_M_facets[__i]));
    00062     }
    00063 #endif
    00064
    00065   // Definitions for static const data members of ctype_base.
    00066   const ctype_base::mask ctype_base::space;
    00067   const ctype_base::mask ctype_base::print;
    00068   const ctype_base::mask ctype_base::cntrl;
    00069   const ctype_base::mask ctype_base::upper;
    00070   const ctype_base::mask ctype_base::lower;
    00071   const ctype_base::mask ctype_base::alpha;
    00072   const ctype_base::mask ctype_base::digit;
    00073   const ctype_base::mask ctype_base::punct;
    00074   const ctype_base::mask ctype_base::xdigit;
    00075   const ctype_base::mask ctype_base::alnum;
    00076   const ctype_base::mask ctype_base::graph;
    00077
    00078   const size_t ctype<char>::table_size;
    00079
    00080   ctype<char>::~ctype()
    00081   {
    00082     _S_destroy_c_locale(_M_c_locale_ctype);
    00083     if (_M_del)
    00084       delete[] this->table();
    00085   }
    00086
    00087   // These are dummy placeholders as these virtual functions are never called.
    00088   bool
    00089   ctype<char>::do_is(mask, char_type) const
    00090   { return false; }
    00091
    00092   const char*
    00093   ctype<char>::do_is(const char_type* __c, const char_type*, mask*) const
    00094   { return __c; }
    00095
    00096   const char*
    00097   ctype<char>::do_scan_is(mask, const char_type* __c, const char_type*) const
    00098   { return __c; }
    00099
    00100   const char*
    00101   ctype<char>::do_scan_not(mask, const char_type* __c, const char_type*) const
    00102   { return __c; }
    00103
    00104   char
    00105   ctype<char>::do_widen(char __c) const
    00106   { return __c; }
    00107
    00108   const char*
    00109   ctype<char>::do_widen(const char* __lo, const char* __hi, char* __dest) const
    00110   {
    00111     memcpy(__dest, __lo, __hi - __lo);
    00112     return __hi;
    00113   }
    00114
    00115   char
    00116   ctype<char>::do_narrow(char __c, char /*__dfault*/) const
    00117   { return __c; }
    00118
    00119   const char*
    00120   ctype<char>::do_narrow(const char* __lo, const char* __hi,
    00121              char /*__dfault*/, char* __dest) const
    00122   {
    00123     memcpy(__dest, __lo, __hi - __lo);
    00124     return __hi;
    00125   }
    00126
    00127 #ifdef _GLIBCPP_USE_WCHAR_T
    00128   ctype<wchar_t>::ctype(size_t __refs)
    00129   : __ctype_abstract_base<wchar_t>(__refs)
    00130   { _M_c_locale_ctype = _S_c_locale; }
    00131
    00132   ctype<wchar_t>::ctype(__c_locale __cloc, size_t __refs)
    00133   : __ctype_abstract_base<wchar_t>(__refs)
    00134   { _M_c_locale_ctype = _S_clone_c_locale(__cloc); }
    00135
    00136   ctype<wchar_t>::~ctype()
    00137   { _S_destroy_c_locale(_M_c_locale_ctype); }
    00138
    00139   template<>
    00140     ctype_byname<wchar_t>::ctype_byname(const char* __s, size_t __refs)
    00141     : ctype<wchar_t>(__refs)
    00142     {
    00143       _S_destroy_c_locale(_M_c_locale_ctype);
    00144       _S_create_c_locale(_M_c_locale_ctype, __s);
    00145     }
    00146 #endif
    00147 } // namespace std
    00148