]>
Commit | Line | Data |
---|---|---|
07814743 | 1 | // Copyright (C) 2000, 2002 Free Software Foundation, Inc. |
63511623 BK |
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. | |
8 | ||
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. | |
13 | ||
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. | |
18 | ||
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. | |
27 | ||
28 | // Written by Benjamin Kosnik <bkoz@cygnus.com> | |
29 | ||
54c1bf78 | 30 | #include <locale> |
63511623 | 31 | |
33590f13 BK |
32 | namespace std |
33 | { | |
34 | #ifdef _GLIBCPP_USE___ENC_TRAITS | |
0479a462 BK |
35 | // Definitions for static const data members of __enc_traits. |
36 | const int __enc_traits::_S_max_size; | |
33590f13 | 37 | #endif |
0479a462 | 38 | |
63511623 BK |
39 | codecvt<char, char, mbstate_t>:: |
40 | codecvt(size_t __refs) | |
41 | : __codecvt_abstract_base<char, char, mbstate_t>(__refs) | |
42 | { } | |
43 | ||
44 | codecvt<char, char, mbstate_t>:: | |
45 | ~codecvt() { } | |
46 | ||
47 | codecvt_base::result | |
48 | codecvt<char, char, mbstate_t>:: | |
c7e2dba5 | 49 | do_out(state_type&, const intern_type* __from, |
63511623 BK |
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 | |
53 | { | |
a5834d1b BK |
54 | size_t __len = min(__from_end - __from, __to_end - __to); |
55 | memcpy(__to, __from, __len); | |
63511623 BK |
56 | __from_next = __from; |
57 | __to_next = __to; | |
58 | return noconv; | |
59 | } | |
60 | ||
61 | codecvt_base::result | |
62 | codecvt<char, char, mbstate_t>:: | |
c7e2dba5 BK |
63 | do_unshift(state_type&, extern_type* __to, |
64 | extern_type*, extern_type*& __to_next) const | |
63511623 BK |
65 | { |
66 | __to_next = __to; | |
67 | return noconv; | |
68 | } | |
69 | ||
70 | codecvt_base::result | |
71 | codecvt<char, char, mbstate_t>:: | |
c7e2dba5 | 72 | do_in(state_type&, const extern_type* __from, |
63511623 BK |
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 | |
76 | { | |
a5834d1b BK |
77 | size_t __len = min(__from_end - __from, __to_end - __to); |
78 | memcpy(__to, __from, __len); | |
63511623 BK |
79 | __from_next = __from; |
80 | __to_next = __to; | |
81 | return noconv; | |
82 | } | |
83 | ||
84 | int | |
85 | codecvt<char, char, mbstate_t>:: | |
a5834d1b BK |
86 | do_encoding() const throw() |
87 | { return 1; } | |
63511623 BK |
88 | |
89 | bool | |
90 | codecvt<char, char, mbstate_t>:: | |
a5834d1b BK |
91 | do_always_noconv() const throw() |
92 | { return true; } | |
63511623 BK |
93 | |
94 | int | |
95 | codecvt<char, char, mbstate_t>:: | |
c7e2dba5 | 96 | do_length (const state_type&, const extern_type* __from, |
63511623 | 97 | const extern_type* __end, size_t __max) const |
a5834d1b | 98 | { return min(__max, static_cast<size_t>(__end - __from)); } |
63511623 BK |
99 | |
100 | int | |
101 | codecvt<char, char, mbstate_t>:: | |
a5834d1b BK |
102 | do_max_length() const throw() |
103 | { return 1; } | |
63511623 | 104 | |
63511623 | 105 | #ifdef _GLIBCPP_USE_WCHAR_T |
a5834d1b | 106 | // codecvt<wchar_t, char, mbstate_t> required specialization |
63511623 BK |
107 | codecvt<wchar_t, char, mbstate_t>:: |
108 | codecvt(size_t __refs) | |
109 | : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs) { } | |
110 | ||
111 | codecvt<wchar_t, char, mbstate_t>:: | |
112 | ~codecvt() { } | |
113 | ||
114 | codecvt_base::result | |
115 | codecvt<wchar_t, char, mbstate_t>:: | |
a5834d1b | 116 | do_out(state_type& __state, const intern_type* __from, |
63511623 | 117 | const intern_type* __from_end, const intern_type*& __from_next, |
a5834d1b | 118 | extern_type* __to, extern_type* __to_end, |
63511623 BK |
119 | extern_type*& __to_next) const |
120 | { | |
a5834d1b BK |
121 | result __ret = error; |
122 | size_t __len = min(__from_end - __from, __to_end - __to); | |
123 | size_t __conv = wcsrtombs(__to, &__from, __len, &__state); | |
124 | ||
125 | if (__conv == __len) | |
126 | { | |
127 | __from_next = __from; | |
128 | __to_next = __to + __conv; | |
129 | __ret = ok; | |
130 | } | |
131 | else if (__conv > 0 && __conv < __len) | |
132 | { | |
133 | __from_next = __from; | |
134 | __to_next = __to + __conv; | |
135 | __ret = partial; | |
136 | } | |
137 | else | |
138 | __ret = error; | |
139 | ||
140 | return __ret; | |
63511623 BK |
141 | } |
142 | ||
143 | codecvt_base::result | |
144 | codecvt<wchar_t, char, mbstate_t>:: | |
c7e2dba5 BK |
145 | do_unshift(state_type&, extern_type* __to, |
146 | extern_type*, extern_type*& __to_next) const | |
63511623 BK |
147 | { |
148 | __to_next = __to; | |
149 | return noconv; | |
150 | } | |
151 | ||
152 | codecvt_base::result | |
153 | codecvt<wchar_t, char, mbstate_t>:: | |
a5834d1b | 154 | do_in(state_type& __state, const extern_type* __from, |
63511623 | 155 | const extern_type* __from_end, const extern_type*& __from_next, |
a5834d1b | 156 | intern_type* __to, intern_type* __to_end, |
63511623 BK |
157 | intern_type*& __to_next) const |
158 | { | |
a5834d1b BK |
159 | result __ret = error; |
160 | size_t __len = min(__from_end - __from, __to_end - __to); | |
161 | size_t __conv = mbsrtowcs(__to, &__from, __len, &__state); | |
162 | ||
163 | if (__conv == __len) | |
164 | { | |
165 | __from_next = __from; | |
166 | __to_next = __to + __conv; | |
167 | __ret = ok; | |
168 | } | |
169 | else if (__conv > 0 && __conv < __len) | |
170 | { | |
171 | __from_next = __from; | |
172 | __to_next = __to + __conv; | |
173 | __ret = partial; | |
174 | } | |
175 | else | |
176 | __ret = error; | |
177 | ||
178 | return __ret; | |
63511623 BK |
179 | } |
180 | ||
181 | int | |
182 | codecvt<wchar_t, char, mbstate_t>:: | |
183 | do_encoding() const throw() | |
07814743 | 184 | { return sizeof(wchar_t); } |
63511623 BK |
185 | |
186 | bool | |
187 | codecvt<wchar_t, char, mbstate_t>:: | |
188 | do_always_noconv() const throw() | |
189 | { return false; } | |
190 | ||
191 | int | |
192 | codecvt<wchar_t, char, mbstate_t>:: | |
c7e2dba5 | 193 | do_length(const state_type&, const extern_type* __from, |
63511623 | 194 | const extern_type* __end, size_t __max) const |
a5834d1b BK |
195 | { return min(__max, static_cast<size_t>(__end - __from)); } |
196 | ||
63511623 | 197 | int |
a5834d1b BK |
198 | codecvt<wchar_t, char, mbstate_t>:: |
199 | do_max_length() const throw() | |
63511623 | 200 | { return 1; } |
63511623 | 201 | #endif // _GLIBCPP_USE_WCHAR_T |
63511623 | 202 | } // namespace std |