1 // Copyright (C) 2000-2021 Free Software Foundation, Inc. 2 // 3 // This file is part of the GNU ISO C++ Library. This library is free 4 // software; you can redistribute it and/or modify it under the 5 // terms of the GNU General Public License as published by the 6 // Free Software Foundation; either version 3, or (at your option) 7 // any later version. 8 9 // This library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 14 // Under Section 7 of GPL version 3, you are granted additional 15 // permissions described in the GCC Runtime Library Exception, version 16 // 3.1, as published by the Free Software Foundation. 17 18 // You should have received a copy of the GNU General Public License and 19 // a copy of the GCC Runtime Library Exception along with this program; 20 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 21 // <http://www.gnu.org/licenses/>. 22 23 // Written by Benjamin Kosnik <bkoz@redhat.com> 24 25 #include <locale> 26 27 namespace std _GLIBCXX_VISIBILITY(default) 28 { 29 _GLIBCXX_BEGIN_NAMESPACE_VERSION 30 31 // Definitions for locale::id of standard facets that are specialized. 32 locale::id codecvt<char, char, mbstate_t>::id; 33 34 #ifdef _GLIBCXX_USE_WCHAR_T 35 locale::id codecvt<wchar_t, char, mbstate_t>::id; 36 #endif 37 38 codecvt<char, char, mbstate_t>:: codecvt(size_t __refs)39 codecvt(size_t __refs) 40 : __codecvt_abstract_base<char, char, mbstate_t>(__refs), 41 _M_c_locale_codecvt(_S_get_c_locale()) 42 { } 43 44 codecvt<char, char, mbstate_t>:: codecvt(__c_locale __cloc,size_t __refs)45 codecvt(__c_locale __cloc, size_t __refs) 46 : __codecvt_abstract_base<char, char, mbstate_t>(__refs), 47 _M_c_locale_codecvt(_S_clone_c_locale(__cloc)) 48 { } 49 50 codecvt<char, char, mbstate_t>:: ~codecvt()51 ~codecvt() 52 { _S_destroy_c_locale(_M_c_locale_codecvt); } 53 54 codecvt_base::result 55 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) const56 do_out(state_type&, const intern_type* __from, 57 const intern_type*, const intern_type*& __from_next, 58 extern_type* __to, extern_type*, 59 extern_type*& __to_next) const 60 { 61 // _GLIBCXX_RESOLVE_LIB_DEFECTS 62 // According to the resolution of DR19, "If returns noconv [...] 63 // there are no changes to the values in [to, to_limit)." 64 __from_next = __from; 65 __to_next = __to; 66 return noconv; 67 } 68 69 codecvt_base::result 70 codecvt<char, char, mbstate_t>:: do_unshift(state_type &,extern_type * __to,extern_type *,extern_type * & __to_next) const71 do_unshift(state_type&, extern_type* __to, 72 extern_type*, extern_type*& __to_next) const 73 { 74 __to_next = __to; 75 return noconv; 76 } 77 78 codecvt_base::result 79 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) const80 do_in(state_type&, const extern_type* __from, 81 const extern_type*, const extern_type*& __from_next, 82 intern_type* __to, intern_type*, intern_type*& __to_next) const 83 { 84 // _GLIBCXX_RESOLVE_LIB_DEFECTS 85 // According to the resolution of DR19, "If returns noconv [...] 86 // there are no changes to the values in [to, to_limit)." 87 __from_next = __from; 88 __to_next = __to; 89 return noconv; 90 } 91 92 int 93 codecvt<char, char, mbstate_t>:: do_encoding() const94 do_encoding() const throw() 95 { return 1; } 96 97 bool 98 codecvt<char, char, mbstate_t>:: do_always_noconv() const99 do_always_noconv() const throw() 100 { return true; } 101 102 int 103 codecvt<char, char, mbstate_t>:: do_length(state_type &,const extern_type * __from,const extern_type * __end,size_t __max) const104 do_length (state_type&, const extern_type* __from, 105 const extern_type* __end, size_t __max) const 106 { 107 size_t __d = static_cast<size_t>(__end - __from); 108 return std::min(__max, __d); 109 } 110 111 int 112 codecvt<char, char, mbstate_t>:: do_max_length() const113 do_max_length() const throw() 114 { return 1; } 115 116 #ifdef _GLIBCXX_USE_WCHAR_T 117 // codecvt<wchar_t, char, mbstate_t> required specialization 118 codecvt<wchar_t, char, mbstate_t>:: codecvt(size_t __refs)119 codecvt(size_t __refs) 120 : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs), 121 _M_c_locale_codecvt(_S_get_c_locale()) 122 { } 123 124 codecvt<wchar_t, char, mbstate_t>:: codecvt(__c_locale __cloc,size_t __refs)125 codecvt(__c_locale __cloc, size_t __refs) 126 : __codecvt_abstract_base<wchar_t, char, mbstate_t>(__refs), 127 _M_c_locale_codecvt(_S_clone_c_locale(__cloc)) 128 { } 129 130 codecvt<wchar_t, char, mbstate_t>:: ~codecvt()131 ~codecvt() 132 { _S_destroy_c_locale(_M_c_locale_codecvt); } 133 134 codecvt_base::result 135 codecvt<wchar_t, char, mbstate_t>:: do_unshift(state_type &,extern_type * __to,extern_type *,extern_type * & __to_next) const136 do_unshift(state_type&, extern_type* __to, 137 extern_type*, extern_type*& __to_next) const 138 { 139 // XXX Probably wrong for stateful encodings 140 __to_next = __to; 141 return noconv; 142 } 143 144 bool 145 codecvt<wchar_t, char, mbstate_t>:: do_always_noconv() const146 do_always_noconv() const throw() 147 { return false; } 148 #endif // _GLIBCXX_USE_WCHAR_T 149 150 _GLIBCXX_END_NAMESPACE_VERSION 151 } // namespace 152