codecvt.cc revision 103447
1191783Srmacklem// Copyright (C) 2000, 2002 Free Software Foundation, Inc.
2191783Srmacklem//
3191783Srmacklem// This file is part of the GNU ISO C++ Library.  This library is free
4191783Srmacklem// software; you can redistribute it and/or modify it under the
5191783Srmacklem// terms of the GNU General Public License as published by the
6191783Srmacklem// Free Software Foundation; either version 2, or (at your option)
7191783Srmacklem// any later version.
8191783Srmacklem
9191783Srmacklem// This library is distributed in the hope that it will be useful,
10191783Srmacklem// but WITHOUT ANY WARRANTY; without even the implied warranty of
11191783Srmacklem// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12191783Srmacklem// GNU General Public License for more details.
13191783Srmacklem
14191783Srmacklem// You should have received a copy of the GNU General Public License along
15191783Srmacklem// with this library; see the file COPYING.  If not, write to the Free
16191783Srmacklem// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17191783Srmacklem// USA.
18191783Srmacklem
19191783Srmacklem// As a special exception, you may use this file as part of a free software
20191783Srmacklem// library without restriction.  Specifically, if other files instantiate
21191783Srmacklem// templates or use macros or inline functions from this file, or you compile
22191783Srmacklem// this file and link it with other files to produce an executable, this
23191783Srmacklem// file does not by itself cause the resulting executable to be covered by
24191783Srmacklem// the GNU General Public License.  This exception does not however
25191783Srmacklem// invalidate any other reasons why the executable file might be covered by
26191783Srmacklem// the GNU General Public License.
27191783Srmacklem
28191783Srmacklem// Written by Benjamin Kosnik <bkoz@cygnus.com>
29191783Srmacklem
30191783Srmacklem#include <locale>
31191783Srmacklem
32191783Srmacklemnamespace std
33191783Srmacklem{
34191783Srmacklem  // Definitions for locale::id of standard facets that are specialized.
35191783Srmacklem locale::id codecvt<char, char, mbstate_t>::id;
36191783Srmacklem
37191783Srmacklem#ifdef _GLIBCPP_USE_WCHAR_T
38191783Srmacklem  locale::id codecvt<wchar_t, char, mbstate_t>::id;
39191783Srmacklem#endif
40191783Srmacklem
41191783Srmacklem#ifdef _GLIBCPP_USE___ENC_TRAITS
42191783Srmacklem  // Definitions for static const data members of __enc_traits.
43191783Srmacklem  const int __enc_traits::_S_max_size;
44191783Srmacklem#endif
45191783Srmacklem
46191783Srmacklem  codecvt<char, char, mbstate_t>::
47191783Srmacklem  codecvt(size_t __refs)
48191783Srmacklem  : __codecvt_abstract_base<char, char, mbstate_t>(__refs)
49191783Srmacklem  { }
50191783Srmacklem
51191783Srmacklem  codecvt<char, char, mbstate_t>::
52191783Srmacklem  ~codecvt()
53191783Srmacklem   { }
54191783Srmacklem
55191783Srmacklem  codecvt_base::result
56191783Srmacklem  codecvt<char, char, mbstate_t>::
57191783Srmacklem  do_out(state_type&, const intern_type* __from,
58191783Srmacklem	 const intern_type* __from_end, const intern_type*& __from_next,
59191783Srmacklem	 extern_type* __to, extern_type* __to_end,
60191783Srmacklem	 extern_type*& __to_next) const
61191783Srmacklem  {
62191783Srmacklem    size_t __len = min(__from_end - __from, __to_end - __to);
63191783Srmacklem    memcpy(__to, __from, __len);
64191783Srmacklem    __from_next = __from;
65191783Srmacklem    __to_next = __to;
66191783Srmacklem    return noconv;
67191783Srmacklem  }
68191783Srmacklem
69191783Srmacklem  codecvt_base::result
70191783Srmacklem  codecvt<char, char, mbstate_t>::
71191783Srmacklem  do_unshift(state_type&, extern_type* __to,
72191783Srmacklem             extern_type*, extern_type*& __to_next) const
73191783Srmacklem  {
74191783Srmacklem    __to_next = __to;
75191783Srmacklem    return noconv;
76191783Srmacklem  }
77191783Srmacklem
78191783Srmacklem  codecvt_base::result
79191783Srmacklem  codecvt<char, char, mbstate_t>::
80191783Srmacklem  do_in(state_type&, const extern_type* __from,
81191783Srmacklem	const extern_type* __from_end, const extern_type*& __from_next,
82191783Srmacklem	intern_type* __to, intern_type* __to_end,
83191783Srmacklem	intern_type*& __to_next) const
84191783Srmacklem  {
85191783Srmacklem    size_t __len = min(__from_end - __from, __to_end - __to);
86191783Srmacklem    memcpy(__to, __from, __len);
87191783Srmacklem    __from_next = __from;
88191783Srmacklem    __to_next = __to;
89191783Srmacklem    return noconv;
90191783Srmacklem  }
91191783Srmacklem
92191783Srmacklem  int
93191783Srmacklem  codecvt<char, char, mbstate_t>::
94191783Srmacklem  do_encoding() const throw()
95191783Srmacklem  { return 1; }
96191783Srmacklem
97191783Srmacklem  bool
98191783Srmacklem  codecvt<char, char, mbstate_t>::
99191783Srmacklem  do_always_noconv() const throw()
100191783Srmacklem  { return true; }
101191783Srmacklem
102191783Srmacklem  int
103191783Srmacklem  codecvt<char, char, mbstate_t>::
104191783Srmacklem  do_length (const state_type&, const extern_type* __from,
105191783Srmacklem	     const extern_type* __end, size_t __max) const
106191783Srmacklem  { return min(__max, static_cast<size_t>(__end - __from)); }
107191783Srmacklem
108191783Srmacklem  int
109191783Srmacklem  codecvt<char, char, mbstate_t>::
110191783Srmacklem  do_max_length() const throw()
111191783Srmacklem  { return 1; }
112191783Srmacklem
113191783Srmacklem#ifdef _GLIBCPP_USE_WCHAR_T
114191783Srmacklem  // codecvt<wchar_t, char, mbstate_t> required specialization
115191783Srmacklem  codecvt<wchar_t, char, mbstate_t>::
116191783Srmacklem  codecvt(size_t __refs)
117191783Srmacklem  : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs)
118191783Srmacklem  { }
119191783Srmacklem
120191783Srmacklem  codecvt<wchar_t, char, mbstate_t>::
121191783Srmacklem  ~codecvt()
122191783Srmacklem  { }
123191783Srmacklem
124191783Srmacklem  codecvt_base::result
125191783Srmacklem  codecvt<wchar_t, char, mbstate_t>::
126191783Srmacklem  do_unshift(state_type&, extern_type* __to,
127191783Srmacklem	     extern_type*, extern_type*& __to_next) const
128191783Srmacklem  {
129191783Srmacklem    __to_next = __to;
130191783Srmacklem    return noconv;
131191783Srmacklem  }
132191783Srmacklem
133191783Srmacklem  int
134191783Srmacklem  codecvt<wchar_t, char, mbstate_t>::
135191783Srmacklem  do_encoding() const throw()
136191783Srmacklem  { return sizeof(wchar_t); }
137191783Srmacklem
138191783Srmacklem  bool
139191783Srmacklem  codecvt<wchar_t, char, mbstate_t>::
140191783Srmacklem  do_always_noconv() const throw()
141191783Srmacklem  { return false; }
142191783Srmacklem
143191783Srmacklem  int
144191783Srmacklem  codecvt<wchar_t, char, mbstate_t>::
145191783Srmacklem  do_length(const state_type&, const extern_type* __from,
146191783Srmacklem	    const extern_type* __end, size_t __max) const
147191783Srmacklem  { return min(__max, static_cast<size_t>(__end - __from)); }
148191783Srmacklem
149191783Srmacklem  int
150191783Srmacklem  codecvt<wchar_t, char, mbstate_t>::
151191783Srmacklem  do_max_length() const throw()
152191783Srmacklem  { return 1; }
153191783Srmacklem#endif //  _GLIBCPP_USE_WCHAR_T
154191783Srmacklem} // namespace std
155191783Srmacklem