# codecvt.cc

    00001 // Copyright (C) 2000, 2002, 2003 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 _GLIBCPP_USE_WCHAR_T
    00038   locale::id codecvt<wchar_t, char, mbstate_t>::id;
    00039 #endif
    00040
    00041 #ifdef _GLIBCPP_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   { }
    00050
    00051   codecvt<char, char, mbstate_t>::
    00052   ~codecvt()
    00053   { }
    00054
    00055   codecvt_base::result
    00056   codecvt<char, char, mbstate_t>::
    00057   do_out(state_type&, const intern_type* __from,
    00058      const intern_type*, const intern_type*& __from_next,
    00059      extern_type* __to, extern_type*,
    00060      extern_type*& __to_next) const
    00061   {
    00062     // _GLIBCPP_RESOLVE_LIB_DEFECTS
    00063     // According to the resolution of DR19, "If returns noconv [...]
    00064     // there are no changes to the values in [to, to_limit)."
    00065     __from_next = __from;
    00066     __to_next = __to;
    00067     return noconv;
    00068   }
    00069
    00070   codecvt_base::result
    00071   codecvt<char, char, mbstate_t>::
    00072   do_unshift(state_type&, extern_type* __to,
    00073              extern_type*, extern_type*& __to_next) const
    00074   {
    00075     __to_next = __to;
    00076     return noconv;
    00077   }
    00078
    00079   codecvt_base::result
    00080   codecvt<char, char, mbstate_t>::
    00081   do_in(state_type&, const extern_type* __from,
    00082     const extern_type*, const extern_type*& __from_next,
    00083     intern_type* __to, intern_type*,
    00084     intern_type*& __to_next) const
    00085   {
    00086     // _GLIBCPP_RESOLVE_LIB_DEFECTS
    00087     // According to the resolution of DR19, "If returns noconv [...]
    00088     // there are no changes to the values in [to, to_limit)."
    00089     __from_next = __from;
    00090     __to_next = __to;
    00091     return noconv;
    00092   }
    00093
    00094   int
    00095   codecvt<char, char, mbstate_t>::
    00096   do_encoding() const throw()
    00097   { return 1; }
    00098
    00099   bool
    00100   codecvt<char, char, mbstate_t>::
    00101   do_always_noconv() const throw()
    00102   { return true; }
    00103
    00104   int
    00105   codecvt<char, char, mbstate_t>::
    00106   do_length (const state_type&, const extern_type* __from,
    00107          const extern_type* __end, size_t __max) const
    00108   { return min(__max, static_cast<size_t>(__end - __from)); }
    00109
    00110   int
    00111   codecvt<char, char, mbstate_t>::
    00112   do_max_length() const throw()
    00113   { return 1; }
    00114
    00115 #ifdef _GLIBCPP_USE_WCHAR_T
    00116   // codecvt<wchar_t, char, mbstate_t> required specialization
    00117   codecvt<wchar_t, char, mbstate_t>::
    00118   codecvt(size_t __refs)
    00119   : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs)
    00120   { }
    00121
    00122   codecvt<wchar_t, char, mbstate_t>::
    00123   ~codecvt()
    00124   { }
    00125
    00126   codecvt_base::result
    00127   codecvt<wchar_t, char, mbstate_t>::
    00128   do_unshift(state_type&, extern_type* __to,
    00129          extern_type*, extern_type*& __to_next) const
    00130   {
    00131     __to_next = __to;
    00132     return noconv;
    00133   }
    00134
    00135   int
    00136   codecvt<wchar_t, char, mbstate_t>::
    00137   do_encoding() const throw()
    00138   { return sizeof(wchar_t); }
    00139
    00140   bool
    00141   codecvt<wchar_t, char, mbstate_t>::
    00142   do_always_noconv() const throw()
    00143   { return false; }
    00144
    00145   int
    00146   codecvt<wchar_t, char, mbstate_t>::
    00147   do_length(const state_type&, const extern_type* __from,
    00148         const extern_type* __end, size_t __max) const
    00149   { return min(__max, static_cast<size_t>(__end - __from)); }
    00150
    00151   int
    00152   codecvt<wchar_t, char, mbstate_t>::
    00153   do_max_length() const throw()
    00154   { return 1; }
    00155 #endif //  _GLIBCPP_USE_WCHAR_T
    00156 } // namespace std