# codecvt.cc

    00001 // Copyright (C) 2000, 2002, 2004 Free Software Foundation, Inc.
    00002 //
    00003 // This file is part of the GNU ISO C++ Library.  This library is free
    00004 // software; you can redistribute it and/or modify it under the
    00005 // terms of the GNU General Public License as published by the
    00006 // Free Software Foundation; either version 2, or (at your option)
    00007 // any later version.
    00008
    00009 // This library is distributed in the hope that it will be useful,
    00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012 // GNU General Public License for more details.
    00013
    00014 // You should have received a copy of the GNU General Public License along
    00015 // with this library; see the file COPYING.  If not, write to the Free
    00016 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    00017 // USA.
    00018
    00019 // As a special exception, you may use this file as part of a free software
    00020 // library without restriction.  Specifically, if other files instantiate
    00021 // templates or use macros or inline functions from this file, or you compile
    00022 // this file and link it with other files to produce an executable, this
    00023 // file does not by itself cause the resulting executable to be covered by
    00024 // the GNU General Public License.  This exception does not however
    00025 // invalidate any other reasons why the executable file might be covered by
    00026 // the GNU General Public License.
    00027
    00028 // Written by Benjamin Kosnik <bkoz@cygnus.com>
    00029
    00030 #include <locale>
    00031
    00032 namespace std
    00033 {
    00034   // Definitions for locale::id of standard facets that are specialized.
    00035  locale::id codecvt<char, char, mbstate_t>::id;
    00036
    00037 #ifdef _GLIBCXX_USE_WCHAR_T
    00038   locale::id codecvt<wchar_t, char, mbstate_t>::id;
    00039 #endif
    00040
    00041 #ifdef _GLIBCXX_USE___ENC_TRAITS
    00042   // Definitions for static const data members of __enc_traits.
    00043   const int __enc_traits::_S_max_size;
    00044 #endif
    00045
    00046   codecvt<char, char, mbstate_t>::
    00047   codecvt(size_t __refs)
    00048   : __codecvt_abstract_base<char, char, mbstate_t>(__refs),
    00049   _M_c_locale_codecvt(_S_get_c_locale())
    00050   { }
    00051
    00052   codecvt<char, char, mbstate_t>::
    00053   codecvt(__c_locale __cloc, size_t __refs)
    00054   : __codecvt_abstract_base<char, char, mbstate_t>(__refs),
    00055   _M_c_locale_codecvt(_S_clone_c_locale(__cloc))
    00056   { }
    00057
    00058   codecvt<char, char, mbstate_t>::
    00059   ~codecvt()
    00060   { _S_destroy_c_locale(_M_c_locale_codecvt); }
    00061
    00062   codecvt_base::result
    00063   codecvt<char, char, mbstate_t>::
    00064   do_out(state_type&, const intern_type* __from,
    00065      const intern_type*, const intern_type*& __from_next,
    00066      extern_type* __to, extern_type*,
    00067      extern_type*& __to_next) const
    00068   {
    00069     // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00070     // According to the resolution of DR19, "If returns noconv [...]
    00071     // there are no changes to the values in [to, to_limit)."
    00072     __from_next = __from;
    00073     __to_next = __to;
    00074     return noconv;
    00075   }
    00076
    00077   codecvt_base::result
    00078   codecvt<char, char, mbstate_t>::
    00079   do_unshift(state_type&, extern_type* __to,
    00080              extern_type*, extern_type*& __to_next) const
    00081   {
    00082     __to_next = __to;
    00083     return noconv;
    00084   }
    00085
    00086   codecvt_base::result
    00087   codecvt<char, char, mbstate_t>::
    00088   do_in(state_type&, const extern_type* __from,
    00089     const extern_type*, const extern_type*& __from_next,
    00090     intern_type* __to, intern_type*, intern_type*& __to_next) const
    00091   {
    00092     // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00093     // According to the resolution of DR19, "If returns noconv [...]
    00094     // there are no changes to the values in [to, to_limit)."
    00095     __from_next = __from;
    00096     __to_next = __to;
    00097     return noconv;
    00098   }
    00099
    00100   int
    00101   codecvt<char, char, mbstate_t>::
    00102   do_encoding() const throw()
    00103   { return 1; }
    00104
    00105   bool
    00106   codecvt<char, char, mbstate_t>::
    00107   do_always_noconv() const throw()
    00108   { return true; }
    00109
    00110   int
    00111   codecvt<char, char, mbstate_t>::
    00112   do_length (state_type&, const extern_type* __from,
    00113          const extern_type* __end, size_t __max) const
    00114   {
    00115     size_t __d = static_cast<size_t>(__end - __from);
    00116     return std::min(__max, __d);
    00117   }
    00118
    00119   int
    00120   codecvt<char, char, mbstate_t>::
    00121   do_max_length() const throw()
    00122   { return 1; }
    00123
    00124 #ifdef _GLIBCXX_USE_WCHAR_T
    00125   // codecvt<wchar_t, char, mbstate_t> required specialization
    00126   codecvt<wchar_t, char, mbstate_t>::
    00127   codecvt(size_t __refs)
    00128   : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs),
    00129   _M_c_locale_codecvt(_S_get_c_locale())
    00130   { }
    00131
    00132   codecvt<wchar_t, char, mbstate_t>::
    00133   codecvt(__c_locale __cloc, size_t __refs)
    00134   : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs),
    00135   _M_c_locale_codecvt(_S_clone_c_locale(__cloc))
    00136   { }
    00137
    00138   codecvt<wchar_t, char, mbstate_t>::
    00139   ~codecvt()
    00140   { _S_destroy_c_locale(_M_c_locale_codecvt); }
    00141
    00142   codecvt_base::result
    00143   codecvt<wchar_t, char, mbstate_t>::
    00144   do_unshift(state_type&, extern_type* __to,
    00145          extern_type*, extern_type*& __to_next) const
    00146   {
    00147     // XXX Probably wrong for stateful encodings
    00148     __to_next = __to;
    00149     return noconv;
    00150   }
    00151
    00152   bool
    00153   codecvt<wchar_t, char, mbstate_t>::
    00154   do_always_noconv() const throw()
    00155   { return false; }
    00156 #endif //  _GLIBCXX_USE_WCHAR_T
    00157 } // namespace std