* config/xtensa/xtensa.h (ASM_OUTPUT_POOL_PROLOGUE): Switch
[official-gcc.git] / libstdc++-v3 / src / codecvt.cc
blob032667e3f13307f047b73357a70beedd34c2e1e4
1 // Copyright (C) 2000, 2002 Free Software Foundation, Inc.
2 //
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)
7 // any later version.
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,
17 // USA.
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 <locale>
32 namespace std
34 #ifdef _GLIBCPP_USE___ENC_TRAITS
35 // Definitions for static const data members of __enc_traits.
36 const int __enc_traits::_S_max_size;
37 #endif
39 codecvt<char, char, mbstate_t>::
40 codecvt(size_t __refs)
41 : __codecvt_abstract_base<char, char, mbstate_t>(__refs)
42 { }
44 codecvt<char, char, mbstate_t>::
45 ~codecvt() { }
47 codecvt_base::result
48 codecvt<char, char, mbstate_t>::
49 do_out(state_type&, 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);
56 __from_next = __from;
57 __to_next = __to;
58 return noconv;
61 codecvt_base::result
62 codecvt<char, char, mbstate_t>::
63 do_unshift(state_type&, extern_type* __to,
64 extern_type*, extern_type*& __to_next) const
66 __to_next = __to;
67 return noconv;
70 codecvt_base::result
71 codecvt<char, char, mbstate_t>::
72 do_in(state_type&, 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);
79 __from_next = __from;
80 __to_next = __to;
81 return noconv;
84 int
85 codecvt<char, char, mbstate_t>::
86 do_encoding() const throw()
87 { return 1; }
89 bool
90 codecvt<char, char, mbstate_t>::
91 do_always_noconv() const throw()
92 { return true; }
94 int
95 codecvt<char, char, mbstate_t>::
96 do_length (const state_type&, const extern_type* __from,
97 const extern_type* __end, size_t __max) const
98 { return min(__max, static_cast<size_t>(__end - __from)); }
100 int
101 codecvt<char, char, mbstate_t>::
102 do_max_length() const throw()
103 { return 1; }
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>::
112 ~codecvt() { }
114 codecvt_base::result
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);
125 if (__conv == __len)
127 __from_next = __from;
128 __to_next = __to + __conv;
129 __ret = ok;
131 else if (__conv > 0 && __conv < __len)
133 __from_next = __from;
134 __to_next = __to + __conv;
135 __ret = partial;
137 else
138 __ret = error;
140 return __ret;
143 codecvt_base::result
144 codecvt<wchar_t, char, mbstate_t>::
145 do_unshift(state_type&, extern_type* __to,
146 extern_type*, extern_type*& __to_next) const
148 __to_next = __to;
149 return noconv;
152 codecvt_base::result
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);
163 if (__conv == __len)
165 __from_next = __from;
166 __to_next = __to + __conv;
167 __ret = ok;
169 else if (__conv > 0 && __conv < __len)
171 __from_next = __from;
172 __to_next = __to + __conv;
173 __ret = partial;
175 else
176 __ret = error;
178 return __ret;
181 int
182 codecvt<wchar_t, char, mbstate_t>::
183 do_encoding() const throw()
184 { return sizeof(wchar_t); }
186 bool
187 codecvt<wchar_t, char, mbstate_t>::
188 do_always_noconv() const throw()
189 { return false; }
191 int
192 codecvt<wchar_t, char, mbstate_t>::
193 do_length(const state_type&, const extern_type* __from,
194 const extern_type* __end, size_t __max) const
195 { return min(__max, static_cast<size_t>(__end - __from)); }
197 int
198 codecvt<wchar_t, char, mbstate_t>::
199 do_max_length() const throw()
200 { return 1; }
201 #endif // _GLIBCPP_USE_WCHAR_T
202 } // namespace std