codecvt.cc revision 117397
1117397Skan// Copyright (C) 2000, 2002, 2003 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
37103447Skan#ifdef _GLIBCPP_USE_WCHAR_T
38103447Skan  locale::id codecvt<wchar_t, char, mbstate_t>::id;
39103447Skan#endif
40103447Skan
4197403Sobrien#ifdef _GLIBCPP_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)
4897403Sobrien  : __codecvt_abstract_base<char, char, mbstate_t>(__refs)
4997403Sobrien  { }
5097403Sobrien
5197403Sobrien  codecvt<char, char, mbstate_t>::
52103447Skan  ~codecvt()
53107606Sobrien  { }
5497403Sobrien
5597403Sobrien  codecvt_base::result
5697403Sobrien  codecvt<char, char, mbstate_t>::
5797403Sobrien  do_out(state_type&, const intern_type* __from,
58110614Skan	 const intern_type*, const intern_type*& __from_next,
59110614Skan	 extern_type* __to, extern_type*,
6097403Sobrien	 extern_type*& __to_next) const
6197403Sobrien  {
62110614Skan    // _GLIBCPP_RESOLVE_LIB_DEFECTS
63110614Skan    // According to the resolution of DR19, "If returns noconv [...]
64110614Skan    // there are no changes to the values in [to, to_limit)."
6597403Sobrien    __from_next = __from;
6697403Sobrien    __to_next = __to;
6797403Sobrien    return noconv;
6897403Sobrien  }
6997403Sobrien
7097403Sobrien  codecvt_base::result
7197403Sobrien  codecvt<char, char, mbstate_t>::
7297403Sobrien  do_unshift(state_type&, extern_type* __to,
7397403Sobrien             extern_type*, extern_type*& __to_next) const
7497403Sobrien  {
7597403Sobrien    __to_next = __to;
7697403Sobrien    return noconv;
7797403Sobrien  }
7897403Sobrien
7997403Sobrien  codecvt_base::result
8097403Sobrien  codecvt<char, char, mbstate_t>::
8197403Sobrien  do_in(state_type&, const extern_type* __from,
82110614Skan	const extern_type*, const extern_type*& __from_next,
83110614Skan	intern_type* __to, intern_type*,
8497403Sobrien	intern_type*& __to_next) const
85117397Skan  {
86110614Skan    // _GLIBCPP_RESOLVE_LIB_DEFECTS
87110614Skan    // According to the resolution of DR19, "If returns noconv [...]
88110614Skan    // there are no changes to the values in [to, to_limit)."
8997403Sobrien    __from_next = __from;
9097403Sobrien    __to_next = __to;
9197403Sobrien    return noconv;
9297403Sobrien  }
9397403Sobrien
9497403Sobrien  int
9597403Sobrien  codecvt<char, char, mbstate_t>::
9697403Sobrien  do_encoding() const throw()
9797403Sobrien  { return 1; }
9897403Sobrien
9997403Sobrien  bool
10097403Sobrien  codecvt<char, char, mbstate_t>::
10197403Sobrien  do_always_noconv() const throw()
10297403Sobrien  { return true; }
10397403Sobrien
10497403Sobrien  int
10597403Sobrien  codecvt<char, char, mbstate_t>::
10697403Sobrien  do_length (const state_type&, const extern_type* __from,
10797403Sobrien	     const extern_type* __end, size_t __max) const
10897403Sobrien  { return min(__max, static_cast<size_t>(__end - __from)); }
10997403Sobrien
11097403Sobrien  int
11197403Sobrien  codecvt<char, char, mbstate_t>::
11297403Sobrien  do_max_length() const throw()
11397403Sobrien  { return 1; }
11497403Sobrien
11597403Sobrien#ifdef _GLIBCPP_USE_WCHAR_T
11697403Sobrien  // codecvt<wchar_t, char, mbstate_t> required specialization
11797403Sobrien  codecvt<wchar_t, char, mbstate_t>::
11897403Sobrien  codecvt(size_t __refs)
119103447Skan  : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs)
120103447Skan  { }
12197403Sobrien
12297403Sobrien  codecvt<wchar_t, char, mbstate_t>::
123103447Skan  ~codecvt()
124103447Skan  { }
12597403Sobrien
12697403Sobrien  codecvt_base::result
12797403Sobrien  codecvt<wchar_t, char, mbstate_t>::
12897403Sobrien  do_unshift(state_type&, extern_type* __to,
12997403Sobrien	     extern_type*, extern_type*& __to_next) const
13097403Sobrien  {
13197403Sobrien    __to_next = __to;
13297403Sobrien    return noconv;
13397403Sobrien  }
13497403Sobrien
13597403Sobrien  int
13697403Sobrien  codecvt<wchar_t, char, mbstate_t>::
13797403Sobrien  do_encoding() const throw()
13897403Sobrien  { return sizeof(wchar_t); }
13997403Sobrien
14097403Sobrien  bool
14197403Sobrien  codecvt<wchar_t, char, mbstate_t>::
14297403Sobrien  do_always_noconv() const throw()
14397403Sobrien  { return false; }
14497403Sobrien
14597403Sobrien  int
14697403Sobrien  codecvt<wchar_t, char, mbstate_t>::
14797403Sobrien  do_length(const state_type&, const extern_type* __from,
14897403Sobrien	    const extern_type* __end, size_t __max) const
14997403Sobrien  { return min(__max, static_cast<size_t>(__end - __from)); }
15097403Sobrien
15197403Sobrien  int
15297403Sobrien  codecvt<wchar_t, char, mbstate_t>::
15397403Sobrien  do_max_length() const throw()
15497403Sobrien  { return 1; }
15597403Sobrien#endif //  _GLIBCPP_USE_WCHAR_T
15697403Sobrien} // namespace std
157