]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/src/codecvt.cc
localefwd.h (class locale): Add static member _S_num_extra_categories...
[thirdparty/gcc.git] / libstdc++-v3 / src / codecvt.cc
CommitLineData
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
32namespace std
33{
38cca750
BK
34 // Definitions for locale::id of standard facets that are specialized.
35 locale::id codecvt<char, char, mbstate_t>::id;
36
37#ifdef _GLIBCPP_USE_WCHAR_T
38 locale::id codecvt<wchar_t, char, mbstate_t>::id;
39#endif
40
33590f13 41#ifdef _GLIBCPP_USE___ENC_TRAITS
0479a462
BK
42 // Definitions for static const data members of __enc_traits.
43 const int __enc_traits::_S_max_size;
33590f13 44#endif
0479a462 45
63511623
BK
46 codecvt<char, char, mbstate_t>::
47 codecvt(size_t __refs)
48 : __codecvt_abstract_base<char, char, mbstate_t>(__refs)
c6b5df53 49 { _M_c_locale_codecvt = _S_c_locale; }
63511623
BK
50
51 codecvt<char, char, mbstate_t>::
c6b5df53
PC
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()
aa53f832 58 { _S_destroy_c_locale(_M_c_locale_codecvt); }
63511623
BK
59
60 codecvt_base::result
61 codecvt<char, char, mbstate_t>::
c7e2dba5 62 do_out(state_type&, const intern_type* __from,
63511623
BK
63 const intern_type* __from_end, const intern_type*& __from_next,
64 extern_type* __to, extern_type* __to_end,
65 extern_type*& __to_next) const
66 {
a5834d1b
BK
67 size_t __len = min(__from_end - __from, __to_end - __to);
68 memcpy(__to, __from, __len);
63511623
BK
69 __from_next = __from;
70 __to_next = __to;
71 return noconv;
72 }
73
74 codecvt_base::result
75 codecvt<char, char, mbstate_t>::
c7e2dba5
BK
76 do_unshift(state_type&, extern_type* __to,
77 extern_type*, extern_type*& __to_next) const
63511623
BK
78 {
79 __to_next = __to;
80 return noconv;
81 }
82
83 codecvt_base::result
84 codecvt<char, char, mbstate_t>::
c7e2dba5 85 do_in(state_type&, const extern_type* __from,
63511623
BK
86 const extern_type* __from_end, const extern_type*& __from_next,
87 intern_type* __to, intern_type* __to_end,
88 intern_type*& __to_next) const
89 {
a5834d1b
BK
90 size_t __len = min(__from_end - __from, __to_end - __to);
91 memcpy(__to, __from, __len);
63511623
BK
92 __from_next = __from;
93 __to_next = __to;
94 return noconv;
95 }
96
97 int
98 codecvt<char, char, mbstate_t>::
a5834d1b
BK
99 do_encoding() const throw()
100 { return 1; }
63511623
BK
101
102 bool
103 codecvt<char, char, mbstate_t>::
a5834d1b
BK
104 do_always_noconv() const throw()
105 { return true; }
63511623
BK
106
107 int
108 codecvt<char, char, mbstate_t>::
c7e2dba5 109 do_length (const state_type&, const extern_type* __from,
63511623 110 const extern_type* __end, size_t __max) const
a5834d1b 111 { return min(__max, static_cast<size_t>(__end - __from)); }
63511623
BK
112
113 int
114 codecvt<char, char, mbstate_t>::
a5834d1b
BK
115 do_max_length() const throw()
116 { return 1; }
63511623 117
63511623 118#ifdef _GLIBCPP_USE_WCHAR_T
a5834d1b 119 // codecvt<wchar_t, char, mbstate_t> required specialization
63511623
BK
120 codecvt<wchar_t, char, mbstate_t>::
121 codecvt(size_t __refs)
c6b5df53 122 : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs)
aa53f832 123 { _M_c_locale_codecvt = _S_c_locale; }
63511623
BK
124
125 codecvt<wchar_t, char, mbstate_t>::
c6b5df53
PC
126 codecvt(__c_locale __cloc, size_t __refs)
127 : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs)
128 { _M_c_locale_codecvt = _S_clone_c_locale(__cloc); }
129
130 codecvt<wchar_t, char, mbstate_t>::
131 ~codecvt()
aa53f832 132 { _S_destroy_c_locale(_M_c_locale_codecvt); }
63511623 133
63511623
BK
134 codecvt_base::result
135 codecvt<wchar_t, char, mbstate_t>::
c7e2dba5
BK
136 do_unshift(state_type&, extern_type* __to,
137 extern_type*, extern_type*& __to_next) const
63511623
BK
138 {
139 __to_next = __to;
140 return noconv;
141 }
142
63511623
BK
143 int
144 codecvt<wchar_t, char, mbstate_t>::
145 do_encoding() const throw()
07814743 146 { return sizeof(wchar_t); }
63511623
BK
147
148 bool
149 codecvt<wchar_t, char, mbstate_t>::
150 do_always_noconv() const throw()
151 { return false; }
152
153 int
154 codecvt<wchar_t, char, mbstate_t>::
c7e2dba5 155 do_length(const state_type&, const extern_type* __from,
63511623 156 const extern_type* __end, size_t __max) const
a5834d1b
BK
157 { return min(__max, static_cast<size_t>(__end - __from)); }
158
63511623 159 int
a5834d1b
BK
160 codecvt<wchar_t, char, mbstate_t>::
161 do_max_length() const throw()
63511623 162 { return 1; }
63511623 163#endif // _GLIBCPP_USE_WCHAR_T
63511623 164} // namespace std