codecvt.cc revision 132720
1132720Skan// Copyright (C) 2000, 2002, 2004 Free Software Foundation, Inc.
297403Sobrien//
397403Sobrien// This file is part of the GNU ISO C++ Library.  This library is free
497403Sobrien// software; you can redistribute it and/or modify it under the
597403Sobrien// terms of the GNU General Public License as published by the
697403Sobrien// Free Software Foundation; either version 2, or (at your option)
797403Sobrien// any later version.
897403Sobrien
997403Sobrien// This library is distributed in the hope that it will be useful,
1097403Sobrien// but WITHOUT ANY WARRANTY; without even the implied warranty of
1197403Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1297403Sobrien// GNU General Public License for more details.
1397403Sobrien
1497403Sobrien// You should have received a copy of the GNU General Public License along
1597403Sobrien// with this library; see the file COPYING.  If not, write to the Free
1697403Sobrien// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
1797403Sobrien// USA.
1897403Sobrien
1997403Sobrien// As a special exception, you may use this file as part of a free software
2097403Sobrien// library without restriction.  Specifically, if other files instantiate
2197403Sobrien// templates or use macros or inline functions from this file, or you compile
2297403Sobrien// this file and link it with other files to produce an executable, this
2397403Sobrien// file does not by itself cause the resulting executable to be covered by
2497403Sobrien// the GNU General Public License.  This exception does not however
2597403Sobrien// invalidate any other reasons why the executable file might be covered by
2697403Sobrien// the GNU General Public License.
2797403Sobrien
2897403Sobrien// Written by Benjamin Kosnik <bkoz@cygnus.com>
2997403Sobrien
3097403Sobrien#include <locale>
3197403Sobrien
3297403Sobriennamespace std
3397403Sobrien{
34103447Skan  // Definitions for locale::id of standard facets that are specialized.
35103447Skan locale::id codecvt<char, char, mbstate_t>::id;
36103447Skan
37132720Skan#ifdef _GLIBCXX_USE_WCHAR_T
38103447Skan  locale::id codecvt<wchar_t, char, mbstate_t>::id;
39103447Skan#endif
40103447Skan
41132720Skan#ifdef _GLIBCXX_USE___ENC_TRAITS
4297403Sobrien  // Definitions for static const data members of __enc_traits.
4397403Sobrien  const int __enc_traits::_S_max_size;
4497403Sobrien#endif
4597403Sobrien
4697403Sobrien  codecvt<char, char, mbstate_t>::
4797403Sobrien  codecvt(size_t __refs)
48132720Skan  : __codecvt_abstract_base<char, char, mbstate_t>(__refs),
49132720Skan  _M_c_locale_codecvt(_S_get_c_locale())
5097403Sobrien  { }
5197403Sobrien
5297403Sobrien  codecvt<char, char, mbstate_t>::
53132720Skan  codecvt(__c_locale __cloc, size_t __refs)
54132720Skan  : __codecvt_abstract_base<char, char, mbstate_t>(__refs),
55132720Skan  _M_c_locale_codecvt(_S_clone_c_locale(__cloc))
56132720Skan  { }
57132720Skan
58132720Skan  codecvt<char, char, mbstate_t>::
59103447Skan  ~codecvt()
60132720Skan  { _S_destroy_c_locale(_M_c_locale_codecvt); }
6197403Sobrien
6297403Sobrien  codecvt_base::result
6397403Sobrien  codecvt<char, char, mbstate_t>::
6497403Sobrien  do_out(state_type&, const intern_type* __from,
65110614Skan	 const intern_type*, const intern_type*& __from_next,
66110614Skan	 extern_type* __to, extern_type*,
6797403Sobrien	 extern_type*& __to_next) const
6897403Sobrien  {
69132720Skan    // _GLIBCXX_RESOLVE_LIB_DEFECTS
70110614Skan    // According to the resolution of DR19, "If returns noconv [...]
71110614Skan    // there are no changes to the values in [to, to_limit)."
7297403Sobrien    __from_next = __from;
7397403Sobrien    __to_next = __to;
7497403Sobrien    return noconv;
7597403Sobrien  }
7697403Sobrien
7797403Sobrien  codecvt_base::result
7897403Sobrien  codecvt<char, char, mbstate_t>::
7997403Sobrien  do_unshift(state_type&, extern_type* __to,
8097403Sobrien             extern_type*, extern_type*& __to_next) const
8197403Sobrien  {
8297403Sobrien    __to_next = __to;
8397403Sobrien    return noconv;
8497403Sobrien  }
8597403Sobrien
8697403Sobrien  codecvt_base::result
8797403Sobrien  codecvt<char, char, mbstate_t>::
8897403Sobrien  do_in(state_type&, const extern_type* __from,
89110614Skan	const extern_type*, const extern_type*& __from_next,
90132720Skan	intern_type* __to, intern_type*, intern_type*& __to_next) const
91117397Skan  {
92132720Skan    // _GLIBCXX_RESOLVE_LIB_DEFECTS
93110614Skan    // According to the resolution of DR19, "If returns noconv [...]
94110614Skan    // there are no changes to the values in [to, to_limit)."
9597403Sobrien    __from_next = __from;
9697403Sobrien    __to_next = __to;
9797403Sobrien    return noconv;
9897403Sobrien  }
9997403Sobrien
10097403Sobrien  int
10197403Sobrien  codecvt<char, char, mbstate_t>::
10297403Sobrien  do_encoding() const throw()
10397403Sobrien  { return 1; }
10497403Sobrien
10597403Sobrien  bool
10697403Sobrien  codecvt<char, char, mbstate_t>::
10797403Sobrien  do_always_noconv() const throw()
10897403Sobrien  { return true; }
10997403Sobrien
11097403Sobrien  int
11197403Sobrien  codecvt<char, char, mbstate_t>::
112132720Skan  do_length (state_type&, const extern_type* __from,
11397403Sobrien	     const extern_type* __end, size_t __max) const
114132720Skan  {
115132720Skan    size_t __d = static_cast<size_t>(__end - __from);
116132720Skan    return std::min(__max, __d);
117132720Skan  }
11897403Sobrien
11997403Sobrien  int
12097403Sobrien  codecvt<char, char, mbstate_t>::
12197403Sobrien  do_max_length() const throw()
12297403Sobrien  { return 1; }
12397403Sobrien
124132720Skan#ifdef _GLIBCXX_USE_WCHAR_T
12597403Sobrien  // codecvt<wchar_t, char, mbstate_t> required specialization
12697403Sobrien  codecvt<wchar_t, char, mbstate_t>::
12797403Sobrien  codecvt(size_t __refs)
128132720Skan  : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs),
129132720Skan  _M_c_locale_codecvt(_S_get_c_locale())
130103447Skan  { }
13197403Sobrien
13297403Sobrien  codecvt<wchar_t, char, mbstate_t>::
133132720Skan  codecvt(__c_locale __cloc, size_t __refs)
134132720Skan  : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs),
135132720Skan  _M_c_locale_codecvt(_S_clone_c_locale(__cloc))
136132720Skan  { }
137132720Skan
138132720Skan  codecvt<wchar_t, char, mbstate_t>::
139103447Skan  ~codecvt()
140132720Skan  { _S_destroy_c_locale(_M_c_locale_codecvt); }
14197403Sobrien
14297403Sobrien  codecvt_base::result
14397403Sobrien  codecvt<wchar_t, char, mbstate_t>::
14497403Sobrien  do_unshift(state_type&, extern_type* __to,
14597403Sobrien	     extern_type*, extern_type*& __to_next) const
14697403Sobrien  {
147132720Skan    // XXX Probably wrong for stateful encodings
14897403Sobrien    __to_next = __to;
14997403Sobrien    return noconv;
15097403Sobrien  }
15197403Sobrien
15297403Sobrien  bool
15397403Sobrien  codecvt<wchar_t, char, mbstate_t>::
15497403Sobrien  do_always_noconv() const throw()
15597403Sobrien  { return false; }
156132720Skan#endif //  _GLIBCXX_USE_WCHAR_T
15797403Sobrien} // namespace std
158