codecvt.cc revision 107606
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.
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
32namespace 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 _GLIBCPP_USE_WCHAR_T
38  locale::id codecvt<wchar_t, char, mbstate_t>::id;
39#endif
40
41#ifdef _GLIBCPP_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  { }
50
51  codecvt<char, char, mbstate_t>::
52  ~codecvt()
53  { }
54
55  codecvt_base::result
56  codecvt<char, char, mbstate_t>::
57  do_out(state_type&, const intern_type* __from,
58	 const intern_type* __from_end, const intern_type*& __from_next,
59	 extern_type* __to, extern_type* __to_end,
60	 extern_type*& __to_next) const
61  {
62    size_t __len = min(__from_end - __from, __to_end - __to);
63    memcpy(__to, __from, __len);
64    __from_next = __from;
65    __to_next = __to;
66    return noconv;
67  }
68
69  codecvt_base::result
70  codecvt<char, char, mbstate_t>::
71  do_unshift(state_type&, extern_type* __to,
72             extern_type*, extern_type*& __to_next) const
73  {
74    __to_next = __to;
75    return noconv;
76  }
77
78  codecvt_base::result
79  codecvt<char, char, mbstate_t>::
80  do_in(state_type&, const extern_type* __from,
81	const extern_type* __from_end, const extern_type*& __from_next,
82	intern_type* __to, intern_type* __to_end,
83	intern_type*& __to_next) const
84  {
85    size_t __len = min(__from_end - __from, __to_end - __to);
86    memcpy(__to, __from, __len);
87    __from_next = __from;
88    __to_next = __to;
89    return noconv;
90  }
91
92  int
93  codecvt<char, char, mbstate_t>::
94  do_encoding() const throw()
95  { return 1; }
96
97  bool
98  codecvt<char, char, mbstate_t>::
99  do_always_noconv() const throw()
100  { return true; }
101
102  int
103  codecvt<char, char, mbstate_t>::
104  do_length (const state_type&, const extern_type* __from,
105	     const extern_type* __end, size_t __max) const
106  { return min(__max, static_cast<size_t>(__end - __from)); }
107
108  int
109  codecvt<char, char, mbstate_t>::
110  do_max_length() const throw()
111  { return 1; }
112
113#ifdef _GLIBCPP_USE_WCHAR_T
114  // codecvt<wchar_t, char, mbstate_t> required specialization
115  codecvt<wchar_t, char, mbstate_t>::
116  codecvt(size_t __refs)
117  : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs)
118  { }
119
120  codecvt<wchar_t, char, mbstate_t>::
121  ~codecvt()
122  { }
123
124  codecvt_base::result
125  codecvt<wchar_t, char, mbstate_t>::
126  do_unshift(state_type&, extern_type* __to,
127	     extern_type*, extern_type*& __to_next) const
128  {
129    __to_next = __to;
130    return noconv;
131  }
132
133  int
134  codecvt<wchar_t, char, mbstate_t>::
135  do_encoding() const throw()
136  { return sizeof(wchar_t); }
137
138  bool
139  codecvt<wchar_t, char, mbstate_t>::
140  do_always_noconv() const throw()
141  { return false; }
142
143  int
144  codecvt<wchar_t, char, mbstate_t>::
145  do_length(const state_type&, const extern_type* __from,
146	    const extern_type* __end, size_t __max) const
147  { return min(__max, static_cast<size_t>(__end - __from)); }
148
149  int
150  codecvt<wchar_t, char, mbstate_t>::
151  do_max_length() const throw()
152  { return 1; }
153#endif //  _GLIBCPP_USE_WCHAR_T
154} // namespace std
155