Fixups for EDG front end.
[gcc.git] / libstdc++-v3 / src / codecvt.cc
1 // Copyright (C) 2000, 2002, 2004 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.
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
30 #include <locale>
31
32 namespace std
33 {
34 // Definitions for locale::id of standard facets that are specialized.
35 locale::id codecvt<char, char, mbstate_t>::id;
36
37 #ifdef _GLIBCXX_USE_WCHAR_T
38 locale::id codecvt<wchar_t, char, mbstate_t>::id;
39 #endif
40
41 #ifdef _GLIBCXX_USE___ENC_TRAITS
42 // Definitions for static const data members of __enc_traits.
43 const int __enc_traits::_S_max_size;
44 #endif
45
46 codecvt<char, char, mbstate_t>::
47 codecvt(size_t __refs)
48 : __codecvt_abstract_base<char, char, mbstate_t>(__refs)
49 { _M_c_locale_codecvt = _S_get_c_locale(); }
50
51 codecvt<char, char, mbstate_t>::
52 codecvt(__c_locale __cloc, size_t __refs)
53 : __codecvt_abstract_base<char, char, mbstate_t>(__refs)
54 { _M_c_locale_codecvt = _S_clone_c_locale(__cloc); }
55
56 codecvt<char, char, mbstate_t>::
57 ~codecvt()
58 { _S_destroy_c_locale(_M_c_locale_codecvt); }
59
60 codecvt_base::result
61 codecvt<char, char, mbstate_t>::
62 do_out(state_type&, const intern_type* __from,
63 const intern_type*, const intern_type*& __from_next,
64 extern_type* __to, extern_type*,
65 extern_type*& __to_next) const
66 {
67 // _GLIBCXX_RESOLVE_LIB_DEFECTS
68 // According to the resolution of DR19, "If returns noconv [...]
69 // there are no changes to the values in [to, to_limit)."
70 __from_next = __from;
71 __to_next = __to;
72 return noconv;
73 }
74
75 codecvt_base::result
76 codecvt<char, char, mbstate_t>::
77 do_unshift(state_type&, extern_type* __to,
78 extern_type*, extern_type*& __to_next) const
79 {
80 __to_next = __to;
81 return noconv;
82 }
83
84 codecvt_base::result
85 codecvt<char, char, mbstate_t>::
86 do_in(state_type&, const extern_type* __from,
87 const extern_type*, const extern_type*& __from_next,
88 intern_type* __to, intern_type*, intern_type*& __to_next) const
89 {
90 // _GLIBCXX_RESOLVE_LIB_DEFECTS
91 // According to the resolution of DR19, "If returns noconv [...]
92 // there are no changes to the values in [to, to_limit)."
93 __from_next = __from;
94 __to_next = __to;
95 return noconv;
96 }
97
98 int
99 codecvt<char, char, mbstate_t>::
100 do_encoding() const throw()
101 { return 1; }
102
103 bool
104 codecvt<char, char, mbstate_t>::
105 do_always_noconv() const throw()
106 { return true; }
107
108 int
109 codecvt<char, char, mbstate_t>::
110 do_length (state_type&, const extern_type* __from,
111 const extern_type* __end, size_t __max) const
112 {
113 size_t __d = static_cast<size_t>(__end - __from);
114 return std::min(__max, __d);
115 }
116
117 int
118 codecvt<char, char, mbstate_t>::
119 do_max_length() const throw()
120 { return 1; }
121
122 #ifdef _GLIBCXX_USE_WCHAR_T
123 // codecvt<wchar_t, char, mbstate_t> required specialization
124 codecvt<wchar_t, char, mbstate_t>::
125 codecvt(size_t __refs)
126 : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs)
127 { _M_c_locale_codecvt = _S_get_c_locale(); }
128
129 codecvt<wchar_t, char, mbstate_t>::
130 codecvt(__c_locale __cloc, size_t __refs)
131 : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs)
132 { _M_c_locale_codecvt = _S_clone_c_locale(__cloc); }
133
134 codecvt<wchar_t, char, mbstate_t>::
135 ~codecvt()
136 { _S_destroy_c_locale(_M_c_locale_codecvt); }
137
138 codecvt_base::result
139 codecvt<wchar_t, char, mbstate_t>::
140 do_unshift(state_type&, extern_type* __to,
141 extern_type*, extern_type*& __to_next) const
142 {
143 // XXX Probably wrong for stateful encodings
144 __to_next = __to;
145 return noconv;
146 }
147
148 bool
149 codecvt<wchar_t, char, mbstate_t>::
150 do_always_noconv() const throw()
151 { return false; }
152 #endif // _GLIBCXX_USE_WCHAR_T
153 } // namespace std