codecvt.cc

00001 // Copyright (C) 2000, 2002 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   { _M_c_locale_codecvt = _S_c_locale; }
00050 
00051   codecvt<char, char, mbstate_t>::
00052   codecvt(__c_locale __cloc, size_t __refs)
00053   : __codecvt_abstract_base<char, char, mbstate_t>(__refs)
00054   { _M_c_locale_codecvt = _S_clone_c_locale(__cloc); }
00055 
00056   codecvt<char, char, mbstate_t>::
00057   ~codecvt()
00058   { _S_destroy_c_locale(_M_c_locale_codecvt); }
00059   
00060   codecvt_base::result
00061   codecvt<char, char, mbstate_t>::
00062   do_out(state_type&, const intern_type* __from, 
00063      const intern_type* __from_end, const intern_type*& __from_next,
00064      extern_type* __to, extern_type* __to_end, 
00065      extern_type*& __to_next) const
00066   { 
00067     size_t __len = min(__from_end - __from, __to_end - __to);
00068     memcpy(__to, __from, __len);
00069     __from_next = __from; 
00070     __to_next = __to;
00071     return noconv;  
00072   }
00073   
00074   codecvt_base::result
00075   codecvt<char, char, mbstate_t>::
00076   do_unshift(state_type&, extern_type* __to,
00077              extern_type*, extern_type*& __to_next) const
00078   { 
00079     __to_next = __to; 
00080     return noconv; 
00081   }
00082   
00083   codecvt_base::result
00084   codecvt<char, char, mbstate_t>::
00085   do_in(state_type&, const extern_type* __from, 
00086     const extern_type* __from_end, const extern_type*& __from_next,
00087     intern_type* __to, intern_type* __to_end, 
00088     intern_type*& __to_next) const
00089   { 
00090     size_t __len = min(__from_end - __from, __to_end - __to);
00091     memcpy(__to, __from, __len);
00092     __from_next = __from; 
00093     __to_next = __to;
00094     return noconv;  
00095   }
00096 
00097   int 
00098   codecvt<char, char, mbstate_t>::
00099   do_encoding() const throw() 
00100   { return 1; }
00101   
00102   bool 
00103   codecvt<char, char, mbstate_t>::
00104   do_always_noconv() const throw() 
00105   { return true; }
00106   
00107   int 
00108   codecvt<char, char, mbstate_t>::
00109   do_length (const state_type&, const extern_type* __from,
00110          const extern_type* __end, size_t __max) const
00111   { return min(__max, static_cast<size_t>(__end - __from)); }
00112   
00113   int 
00114   codecvt<char, char, mbstate_t>::
00115   do_max_length() const throw() 
00116   { return 1; }
00117   
00118 #ifdef _GLIBCPP_USE_WCHAR_T
00119   // codecvt<wchar_t, char, mbstate_t> required specialization
00120   codecvt<wchar_t, char, mbstate_t>::
00121   codecvt(size_t __refs)
00122   : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs)
00123   { _M_c_locale_codecvt = _S_c_locale; }
00124 
00125   codecvt<wchar_t, char, mbstate_t>::
00126   codecvt(__c_locale __cloc, size_t __refs)
00127   : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs)
00128   { _M_c_locale_codecvt = _S_clone_c_locale(__cloc); }
00129 
00130   codecvt<wchar_t, char, mbstate_t>::
00131   ~codecvt()
00132   { _S_destroy_c_locale(_M_c_locale_codecvt); }
00133   
00134   codecvt_base::result
00135   codecvt<wchar_t, char, mbstate_t>::
00136   do_unshift(state_type&, extern_type* __to,
00137          extern_type*, extern_type*& __to_next) const
00138   {
00139     __to_next = __to;
00140     return noconv;
00141   }
00142   
00143   int 
00144   codecvt<wchar_t, char, mbstate_t>::
00145   do_encoding() const throw()
00146   { return sizeof(wchar_t); }
00147   
00148   bool 
00149   codecvt<wchar_t, char, mbstate_t>::
00150   do_always_noconv() const throw()
00151   { return false; }
00152   
00153   int 
00154   codecvt<wchar_t, char, mbstate_t>::
00155   do_length(const state_type&, const extern_type* __from,
00156         const extern_type* __end, size_t __max) const
00157   { return min(__max, static_cast<size_t>(__end - __from)); }
00158 
00159   int 
00160   codecvt<wchar_t, char, mbstate_t>::
00161   do_max_length() const throw()
00162   { return 1; }
00163 #endif //  _GLIBCPP_USE_WCHAR_T
00164 } // namespace std

Generated on Thu Nov 21 03:12:47 2002 for libstdc++-v3 Source by doxygen1.2.18-20021030