1 // Copyright (C) 2000 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 2, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // As a special exception, you may use this file as part of a free software
20 // library without restriction. Specifically, if other files instantiate
21 // templates or use macros or inline functions from this file, or you compile
22 // this file and link it with other files to produce an executable, this
23 // file does not by itself cause the resulting executable to be covered by
24 // the GNU General Public License. This exception does not however
25 // invalidate any other reasons why the executable file might be covered by
26 // the GNU General Public License.
28 // Written by Benjamin Kosnik <bkoz@cygnus.com>
30 #include <bits/std_locale.h>
34 #ifdef _GLIBCPP_USE___ENC_TRAITS
35 // Definitions for static const data members of __enc_traits.
36 const int __enc_traits::_S_max_size;
39 codecvt<char, char, mbstate_t>::
40 codecvt(size_t __refs)
41 : __codecvt_abstract_base<char, char, mbstate_t>(__refs)
44 codecvt<char, char, mbstate_t>::
48 codecvt<char, char, mbstate_t>::
49 do_out(state_type& /*__state*/, const intern_type* __from,
50 const intern_type* __from_end, const intern_type*& __from_next,
51 extern_type* __to, extern_type* __to_end,
52 extern_type*& __to_next) const
54 size_t __len = min(__from_end - __from, __to_end - __to);
55 memcpy(__to, __from, __len);
62 codecvt<char, char, mbstate_t>::
63 do_unshift(state_type& /*__state*/, extern_type* __to,
64 extern_type* /*__to_end*/, extern_type*& __to_next) const
71 codecvt<char, char, mbstate_t>::
72 do_in(state_type& /*__state*/, const extern_type* __from,
73 const extern_type* __from_end, const extern_type*& __from_next,
74 intern_type* __to, intern_type* __to_end,
75 intern_type*& __to_next) const
77 size_t __len = min(__from_end - __from, __to_end - __to);
78 memcpy(__to, __from, __len);
85 codecvt<char, char, mbstate_t>::
86 do_encoding() const throw()
90 codecvt<char, char, mbstate_t>::
91 do_always_noconv() const throw()
95 codecvt<char, char, mbstate_t>::
96 do_length (const state_type& /*__state*/, const extern_type* __from,
97 const extern_type* __end, size_t __max) const
98 { return min(__max, static_cast<size_t>(__end - __from)); }
101 codecvt<char, char, mbstate_t>::
102 do_max_length() const throw()
105 #ifdef _GLIBCPP_USE_WCHAR_T
106 // codecvt<wchar_t, char, mbstate_t> required specialization
107 codecvt<wchar_t, char, mbstate_t>::
108 codecvt(size_t __refs)
109 : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs) { }
111 codecvt<wchar_t, char, mbstate_t>::
115 codecvt<wchar_t, char, mbstate_t>::
116 do_out(state_type& __state, const intern_type* __from,
117 const intern_type* __from_end, const intern_type*& __from_next,
118 extern_type* __to, extern_type* __to_end,
119 extern_type*& __to_next) const
121 result __ret = error;
122 size_t __len = min(__from_end - __from, __to_end - __to);
123 size_t __conv = wcsrtombs(__to, &__from, __len, &__state);
127 __from_next = __from;
128 __to_next = __to + __conv;
131 else if (__conv > 0 && __conv < __len)
133 __from_next = __from;
134 __to_next = __to + __conv;
144 codecvt<wchar_t, char, mbstate_t>::
145 do_unshift(state_type& /*__state*/, extern_type* __to,
146 extern_type* /*__to_end*/, extern_type*& __to_next) const
153 codecvt<wchar_t, char, mbstate_t>::
154 do_in(state_type& __state, const extern_type* __from,
155 const extern_type* __from_end, const extern_type*& __from_next,
156 intern_type* __to, intern_type* __to_end,
157 intern_type*& __to_next) const
159 result __ret = error;
160 size_t __len = min(__from_end - __from, __to_end - __to);
161 size_t __conv = mbsrtowcs(__to, &__from, __len, &__state);
165 __from_next = __from;
166 __to_next = __to + __conv;
169 else if (__conv > 0 && __conv < __len)
171 __from_next = __from;
172 __to_next = __to + __conv;
182 codecvt<wchar_t, char, mbstate_t>::
183 do_encoding() const throw()
187 codecvt<wchar_t, char, mbstate_t>::
188 do_always_noconv() const throw()
192 codecvt<wchar_t, char, mbstate_t>::
193 do_length(const state_type& /*__state*/, const extern_type* __from,
194 const extern_type* __end, size_t __max) const
195 { return min(__max, static_cast<size_t>(__end - __from)); }
198 codecvt<wchar_t, char, mbstate_t>::
199 do_max_length() const throw()
201 #endif // _GLIBCPP_USE_WCHAR_T