1169691Skan// Copyright (C) 2000, 2002, 2004, 2005 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 16169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 28169691Skan// Written by Benjamin Kosnik <bkoz@redhat.com> 2997403Sobrien 3097403Sobrien#include <locale> 3197403Sobrien 32169691Skan_GLIBCXX_BEGIN_NAMESPACE(std) 33169691Skan 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 4197403Sobrien codecvt<char, char, mbstate_t>:: 4297403Sobrien codecvt(size_t __refs) 43132720Skan : __codecvt_abstract_base<char, char, mbstate_t>(__refs), 44132720Skan _M_c_locale_codecvt(_S_get_c_locale()) 4597403Sobrien { } 4697403Sobrien 4797403Sobrien codecvt<char, char, mbstate_t>:: 48132720Skan codecvt(__c_locale __cloc, size_t __refs) 49132720Skan : __codecvt_abstract_base<char, char, mbstate_t>(__refs), 50132720Skan _M_c_locale_codecvt(_S_clone_c_locale(__cloc)) 51132720Skan { } 52132720Skan 53132720Skan codecvt<char, char, mbstate_t>:: 54103447Skan ~codecvt() 55132720Skan { _S_destroy_c_locale(_M_c_locale_codecvt); } 5697403Sobrien 5797403Sobrien codecvt_base::result 5897403Sobrien codecvt<char, char, mbstate_t>:: 5997403Sobrien do_out(state_type&, const intern_type* __from, 60110614Skan const intern_type*, const intern_type*& __from_next, 61110614Skan extern_type* __to, extern_type*, 6297403Sobrien extern_type*& __to_next) const 6397403Sobrien { 64132720Skan // _GLIBCXX_RESOLVE_LIB_DEFECTS 65110614Skan // According to the resolution of DR19, "If returns noconv [...] 66110614Skan // there are no changes to the values in [to, to_limit)." 6797403Sobrien __from_next = __from; 6897403Sobrien __to_next = __to; 6997403Sobrien return noconv; 7097403Sobrien } 7197403Sobrien 7297403Sobrien codecvt_base::result 7397403Sobrien codecvt<char, char, mbstate_t>:: 7497403Sobrien do_unshift(state_type&, extern_type* __to, 7597403Sobrien extern_type*, extern_type*& __to_next) const 7697403Sobrien { 7797403Sobrien __to_next = __to; 7897403Sobrien return noconv; 7997403Sobrien } 8097403Sobrien 8197403Sobrien codecvt_base::result 8297403Sobrien codecvt<char, char, mbstate_t>:: 8397403Sobrien do_in(state_type&, const extern_type* __from, 84110614Skan const extern_type*, const extern_type*& __from_next, 85132720Skan intern_type* __to, intern_type*, intern_type*& __to_next) const 86117397Skan { 87132720Skan // _GLIBCXX_RESOLVE_LIB_DEFECTS 88110614Skan // According to the resolution of DR19, "If returns noconv [...] 89110614Skan // there are no changes to the values in [to, to_limit)." 9097403Sobrien __from_next = __from; 9197403Sobrien __to_next = __to; 9297403Sobrien return noconv; 9397403Sobrien } 9497403Sobrien 9597403Sobrien int 9697403Sobrien codecvt<char, char, mbstate_t>:: 9797403Sobrien do_encoding() const throw() 9897403Sobrien { return 1; } 9997403Sobrien 10097403Sobrien bool 10197403Sobrien codecvt<char, char, mbstate_t>:: 10297403Sobrien do_always_noconv() const throw() 10397403Sobrien { return true; } 10497403Sobrien 10597403Sobrien int 10697403Sobrien codecvt<char, char, mbstate_t>:: 107132720Skan do_length (state_type&, const extern_type* __from, 10897403Sobrien const extern_type* __end, size_t __max) const 109132720Skan { 110132720Skan size_t __d = static_cast<size_t>(__end - __from); 111132720Skan return std::min(__max, __d); 112132720Skan } 11397403Sobrien 11497403Sobrien int 11597403Sobrien codecvt<char, char, mbstate_t>:: 11697403Sobrien do_max_length() const throw() 11797403Sobrien { return 1; } 11897403Sobrien 119132720Skan#ifdef _GLIBCXX_USE_WCHAR_T 12097403Sobrien // codecvt<wchar_t, char, mbstate_t> required specialization 12197403Sobrien codecvt<wchar_t, char, mbstate_t>:: 12297403Sobrien codecvt(size_t __refs) 123132720Skan : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs), 124132720Skan _M_c_locale_codecvt(_S_get_c_locale()) 125103447Skan { } 12697403Sobrien 12797403Sobrien codecvt<wchar_t, char, mbstate_t>:: 128132720Skan codecvt(__c_locale __cloc, size_t __refs) 129132720Skan : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs), 130132720Skan _M_c_locale_codecvt(_S_clone_c_locale(__cloc)) 131132720Skan { } 132132720Skan 133132720Skan codecvt<wchar_t, char, mbstate_t>:: 134103447Skan ~codecvt() 135132720Skan { _S_destroy_c_locale(_M_c_locale_codecvt); } 13697403Sobrien 13797403Sobrien codecvt_base::result 13897403Sobrien codecvt<wchar_t, char, mbstate_t>:: 13997403Sobrien do_unshift(state_type&, extern_type* __to, 14097403Sobrien extern_type*, extern_type*& __to_next) const 14197403Sobrien { 142132720Skan // XXX Probably wrong for stateful encodings 14397403Sobrien __to_next = __to; 14497403Sobrien return noconv; 14597403Sobrien } 14697403Sobrien 14797403Sobrien bool 14897403Sobrien codecvt<wchar_t, char, mbstate_t>:: 14997403Sobrien do_always_noconv() const throw() 15097403Sobrien { return false; } 151132720Skan#endif // _GLIBCXX_USE_WCHAR_T 152169691Skan 153169691Skan_GLIBCXX_END_NAMESPACE 154