1*404b540aSrobert // Copyright (C) 2000, 2002, 2004, 2005 Free Software Foundation, Inc. 2*404b540aSrobert // 3*404b540aSrobert // This file is part of the GNU ISO C++ Library. This library is free 4*404b540aSrobert // software; you can redistribute it and/or modify it under the 5*404b540aSrobert // terms of the GNU General Public License as published by the 6*404b540aSrobert // Free Software Foundation; either version 2, or (at your option) 7*404b540aSrobert // any later version. 8*404b540aSrobert 9*404b540aSrobert // This library is distributed in the hope that it will be useful, 10*404b540aSrobert // but WITHOUT ANY WARRANTY; without even the implied warranty of 11*404b540aSrobert // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12*404b540aSrobert // GNU General Public License for more details. 13*404b540aSrobert 14*404b540aSrobert // You should have received a copy of the GNU General Public License along 15*404b540aSrobert // with this library; see the file COPYING. If not, write to the Free 16*404b540aSrobert // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 17*404b540aSrobert // USA. 18*404b540aSrobert 19*404b540aSrobert // As a special exception, you may use this file as part of a free software 20*404b540aSrobert // library without restriction. Specifically, if other files instantiate 21*404b540aSrobert // templates or use macros or inline functions from this file, or you compile 22*404b540aSrobert // this file and link it with other files to produce an executable, this 23*404b540aSrobert // file does not by itself cause the resulting executable to be covered by 24*404b540aSrobert // the GNU General Public License. This exception does not however 25*404b540aSrobert // invalidate any other reasons why the executable file might be covered by 26*404b540aSrobert // the GNU General Public License. 27*404b540aSrobert 28*404b540aSrobert // Written by Benjamin Kosnik <bkoz@redhat.com> 29*404b540aSrobert 30*404b540aSrobert #include <locale> 31*404b540aSrobert 32*404b540aSrobert _GLIBCXX_BEGIN_NAMESPACE(std) 33*404b540aSrobert 34*404b540aSrobert // Definitions for locale::id of standard facets that are specialized. 35*404b540aSrobert locale::id codecvt<char, char, mbstate_t>::id; 36*404b540aSrobert 37*404b540aSrobert #ifdef _GLIBCXX_USE_WCHAR_T 38*404b540aSrobert locale::id codecvt<wchar_t, char, mbstate_t>::id; 39*404b540aSrobert #endif 40*404b540aSrobert 41*404b540aSrobert codecvt<char, char, mbstate_t>:: codecvt(size_t __refs)42*404b540aSrobert codecvt(size_t __refs) 43*404b540aSrobert : __codecvt_abstract_base<char, char, mbstate_t>(__refs), 44*404b540aSrobert _M_c_locale_codecvt(_S_get_c_locale()) 45*404b540aSrobert { } 46*404b540aSrobert 47*404b540aSrobert codecvt<char, char, mbstate_t>:: codecvt(__c_locale __cloc,size_t __refs)48*404b540aSrobert codecvt(__c_locale __cloc, size_t __refs) 49*404b540aSrobert : __codecvt_abstract_base<char, char, mbstate_t>(__refs), 50*404b540aSrobert _M_c_locale_codecvt(_S_clone_c_locale(__cloc)) 51*404b540aSrobert { } 52*404b540aSrobert 53*404b540aSrobert codecvt<char, char, mbstate_t>:: ~codecvt()54*404b540aSrobert ~codecvt() 55*404b540aSrobert { _S_destroy_c_locale(_M_c_locale_codecvt); } 56*404b540aSrobert 57*404b540aSrobert codecvt_base::result 58*404b540aSrobert codecvt<char, char, mbstate_t>:: do_out(state_type &,const intern_type * __from,const intern_type *,const intern_type * & __from_next,extern_type * __to,extern_type *,extern_type * & __to_next) const59*404b540aSrobert do_out(state_type&, const intern_type* __from, 60*404b540aSrobert const intern_type*, const intern_type*& __from_next, 61*404b540aSrobert extern_type* __to, extern_type*, 62*404b540aSrobert extern_type*& __to_next) const 63*404b540aSrobert { 64*404b540aSrobert // _GLIBCXX_RESOLVE_LIB_DEFECTS 65*404b540aSrobert // According to the resolution of DR19, "If returns noconv [...] 66*404b540aSrobert // there are no changes to the values in [to, to_limit)." 67*404b540aSrobert __from_next = __from; 68*404b540aSrobert __to_next = __to; 69*404b540aSrobert return noconv; 70*404b540aSrobert } 71*404b540aSrobert 72*404b540aSrobert codecvt_base::result 73*404b540aSrobert codecvt<char, char, mbstate_t>:: do_unshift(state_type &,extern_type * __to,extern_type *,extern_type * & __to_next) const74*404b540aSrobert do_unshift(state_type&, extern_type* __to, 75*404b540aSrobert extern_type*, extern_type*& __to_next) const 76*404b540aSrobert { 77*404b540aSrobert __to_next = __to; 78*404b540aSrobert return noconv; 79*404b540aSrobert } 80*404b540aSrobert 81*404b540aSrobert codecvt_base::result 82*404b540aSrobert codecvt<char, char, mbstate_t>:: do_in(state_type &,const extern_type * __from,const extern_type *,const extern_type * & __from_next,intern_type * __to,intern_type *,intern_type * & __to_next) const83*404b540aSrobert do_in(state_type&, const extern_type* __from, 84*404b540aSrobert const extern_type*, const extern_type*& __from_next, 85*404b540aSrobert intern_type* __to, intern_type*, intern_type*& __to_next) const 86*404b540aSrobert { 87*404b540aSrobert // _GLIBCXX_RESOLVE_LIB_DEFECTS 88*404b540aSrobert // According to the resolution of DR19, "If returns noconv [...] 89*404b540aSrobert // there are no changes to the values in [to, to_limit)." 90*404b540aSrobert __from_next = __from; 91*404b540aSrobert __to_next = __to; 92*404b540aSrobert return noconv; 93*404b540aSrobert } 94*404b540aSrobert 95*404b540aSrobert int 96*404b540aSrobert codecvt<char, char, mbstate_t>:: do_encoding() const97*404b540aSrobert do_encoding() const throw() 98*404b540aSrobert { return 1; } 99*404b540aSrobert 100*404b540aSrobert bool 101*404b540aSrobert codecvt<char, char, mbstate_t>:: do_always_noconv() const102*404b540aSrobert do_always_noconv() const throw() 103*404b540aSrobert { return true; } 104*404b540aSrobert 105*404b540aSrobert int 106*404b540aSrobert codecvt<char, char, mbstate_t>:: do_length(state_type &,const extern_type * __from,const extern_type * __end,size_t __max) const107*404b540aSrobert do_length (state_type&, const extern_type* __from, 108*404b540aSrobert const extern_type* __end, size_t __max) const 109*404b540aSrobert { 110*404b540aSrobert size_t __d = static_cast<size_t>(__end - __from); 111*404b540aSrobert return std::min(__max, __d); 112*404b540aSrobert } 113*404b540aSrobert 114*404b540aSrobert int 115*404b540aSrobert codecvt<char, char, mbstate_t>:: do_max_length() const116*404b540aSrobert do_max_length() const throw() 117*404b540aSrobert { return 1; } 118*404b540aSrobert 119*404b540aSrobert #ifdef _GLIBCXX_USE_WCHAR_T 120*404b540aSrobert // codecvt<wchar_t, char, mbstate_t> required specialization 121*404b540aSrobert codecvt<wchar_t, char, mbstate_t>:: codecvt(size_t __refs)122*404b540aSrobert codecvt(size_t __refs) 123*404b540aSrobert : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs), 124*404b540aSrobert _M_c_locale_codecvt(_S_get_c_locale()) 125*404b540aSrobert { } 126*404b540aSrobert 127*404b540aSrobert codecvt<wchar_t, char, mbstate_t>:: codecvt(__c_locale __cloc,size_t __refs)128*404b540aSrobert codecvt(__c_locale __cloc, size_t __refs) 129*404b540aSrobert : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs), 130*404b540aSrobert _M_c_locale_codecvt(_S_clone_c_locale(__cloc)) 131*404b540aSrobert { } 132*404b540aSrobert 133*404b540aSrobert codecvt<wchar_t, char, mbstate_t>:: ~codecvt()134*404b540aSrobert ~codecvt() 135*404b540aSrobert { _S_destroy_c_locale(_M_c_locale_codecvt); } 136*404b540aSrobert 137*404b540aSrobert codecvt_base::result 138*404b540aSrobert codecvt<wchar_t, char, mbstate_t>:: do_unshift(state_type &,extern_type * __to,extern_type *,extern_type * & __to_next) const139*404b540aSrobert do_unshift(state_type&, extern_type* __to, 140*404b540aSrobert extern_type*, extern_type*& __to_next) const 141*404b540aSrobert { 142*404b540aSrobert // XXX Probably wrong for stateful encodings 143*404b540aSrobert __to_next = __to; 144*404b540aSrobert return noconv; 145*404b540aSrobert } 146*404b540aSrobert 147*404b540aSrobert bool 148*404b540aSrobert codecvt<wchar_t, char, mbstate_t>:: do_always_noconv() const149*404b540aSrobert do_always_noconv() const throw() 150*404b540aSrobert { return false; } 151*404b540aSrobert #endif // _GLIBCXX_USE_WCHAR_T 152*404b540aSrobert 153*404b540aSrobert _GLIBCXX_END_NAMESPACE 154