1*e4b17023SJohn Marino // Locale support (codecvt) -*- C++ -*- 2*e4b17023SJohn Marino 3*e4b17023SJohn Marino // Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 4*e4b17023SJohn Marino // 2009, 2010, 2011 Free Software Foundation, Inc. 5*e4b17023SJohn Marino // 6*e4b17023SJohn Marino // This file is part of the GNU ISO C++ Library. This library is free 7*e4b17023SJohn Marino // software; you can redistribute it and/or modify it under the 8*e4b17023SJohn Marino // terms of the GNU General Public License as published by the 9*e4b17023SJohn Marino // Free Software Foundation; either version 3, or (at your option) 10*e4b17023SJohn Marino // any later version. 11*e4b17023SJohn Marino 12*e4b17023SJohn Marino // This library is distributed in the hope that it will be useful, 13*e4b17023SJohn Marino // but WITHOUT ANY WARRANTY; without even the implied warranty of 14*e4b17023SJohn Marino // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*e4b17023SJohn Marino // GNU General Public License for more details. 16*e4b17023SJohn Marino 17*e4b17023SJohn Marino // Under Section 7 of GPL version 3, you are granted additional 18*e4b17023SJohn Marino // permissions described in the GCC Runtime Library Exception, version 19*e4b17023SJohn Marino // 3.1, as published by the Free Software Foundation. 20*e4b17023SJohn Marino 21*e4b17023SJohn Marino // You should have received a copy of the GNU General Public License and 22*e4b17023SJohn Marino // a copy of the GCC Runtime Library Exception along with this program; 23*e4b17023SJohn Marino // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 24*e4b17023SJohn Marino // <http://www.gnu.org/licenses/>. 25*e4b17023SJohn Marino 26*e4b17023SJohn Marino /** @file bits/codecvt.h 27*e4b17023SJohn Marino * This is an internal header file, included by other library headers. 28*e4b17023SJohn Marino * Do not attempt to use it directly. @headername{locale} 29*e4b17023SJohn Marino */ 30*e4b17023SJohn Marino 31*e4b17023SJohn Marino // 32*e4b17023SJohn Marino // ISO C++ 14882: 22.2.1.5 Template class codecvt 33*e4b17023SJohn Marino // 34*e4b17023SJohn Marino 35*e4b17023SJohn Marino // Written by Benjamin Kosnik <bkoz@redhat.com> 36*e4b17023SJohn Marino 37*e4b17023SJohn Marino #ifndef _CODECVT_H 38*e4b17023SJohn Marino #define _CODECVT_H 1 39*e4b17023SJohn Marino 40*e4b17023SJohn Marino #pragma GCC system_header 41*e4b17023SJohn Marino 42*e4b17023SJohn Marino namespace std _GLIBCXX_VISIBILITY(default) 43*e4b17023SJohn Marino { 44*e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_VERSION 45*e4b17023SJohn Marino 46*e4b17023SJohn Marino /// Empty base class for codecvt facet [22.2.1.5]. 47*e4b17023SJohn Marino class codecvt_base 48*e4b17023SJohn Marino { 49*e4b17023SJohn Marino public: 50*e4b17023SJohn Marino enum result 51*e4b17023SJohn Marino { 52*e4b17023SJohn Marino ok, 53*e4b17023SJohn Marino partial, 54*e4b17023SJohn Marino error, 55*e4b17023SJohn Marino noconv 56*e4b17023SJohn Marino }; 57*e4b17023SJohn Marino }; 58*e4b17023SJohn Marino 59*e4b17023SJohn Marino /** 60*e4b17023SJohn Marino * @brief Common base for codecvt functions. 61*e4b17023SJohn Marino * 62*e4b17023SJohn Marino * This template class provides implementations of the public functions 63*e4b17023SJohn Marino * that forward to the protected virtual functions. 64*e4b17023SJohn Marino * 65*e4b17023SJohn Marino * This template also provides abstract stubs for the protected virtual 66*e4b17023SJohn Marino * functions. 67*e4b17023SJohn Marino */ 68*e4b17023SJohn Marino template<typename _InternT, typename _ExternT, typename _StateT> 69*e4b17023SJohn Marino class __codecvt_abstract_base 70*e4b17023SJohn Marino : public locale::facet, public codecvt_base 71*e4b17023SJohn Marino { 72*e4b17023SJohn Marino public: 73*e4b17023SJohn Marino // Types: 74*e4b17023SJohn Marino typedef codecvt_base::result result; 75*e4b17023SJohn Marino typedef _InternT intern_type; 76*e4b17023SJohn Marino typedef _ExternT extern_type; 77*e4b17023SJohn Marino typedef _StateT state_type; 78*e4b17023SJohn Marino 79*e4b17023SJohn Marino // 22.2.1.5.1 codecvt members 80*e4b17023SJohn Marino /** 81*e4b17023SJohn Marino * @brief Convert from internal to external character set. 82*e4b17023SJohn Marino * 83*e4b17023SJohn Marino * Converts input string of intern_type to output string of 84*e4b17023SJohn Marino * extern_type. This is analogous to wcsrtombs. It does this by 85*e4b17023SJohn Marino * calling codecvt::do_out. 86*e4b17023SJohn Marino * 87*e4b17023SJohn Marino * The source and destination character sets are determined by the 88*e4b17023SJohn Marino * facet's locale, internal and external types. 89*e4b17023SJohn Marino * 90*e4b17023SJohn Marino * The characters in [from,from_end) are converted and written to 91*e4b17023SJohn Marino * [to,to_end). from_next and to_next are set to point to the 92*e4b17023SJohn Marino * character following the last successfully converted character, 93*e4b17023SJohn Marino * respectively. If the result needed no conversion, from_next and 94*e4b17023SJohn Marino * to_next are not affected. 95*e4b17023SJohn Marino * 96*e4b17023SJohn Marino * The @a state argument should be initialized if the input is at the 97*e4b17023SJohn Marino * beginning and carried from a previous call if continuing 98*e4b17023SJohn Marino * conversion. There are no guarantees about how @a state is used. 99*e4b17023SJohn Marino * 100*e4b17023SJohn Marino * The result returned is a member of codecvt_base::result. If 101*e4b17023SJohn Marino * all the input is converted, returns codecvt_base::ok. If no 102*e4b17023SJohn Marino * conversion is necessary, returns codecvt_base::noconv. If 103*e4b17023SJohn Marino * the input ends early or there is insufficient space in the 104*e4b17023SJohn Marino * output, returns codecvt_base::partial. Otherwise the 105*e4b17023SJohn Marino * conversion failed and codecvt_base::error is returned. 106*e4b17023SJohn Marino * 107*e4b17023SJohn Marino * @param __state Persistent conversion state data. 108*e4b17023SJohn Marino * @param __from Start of input. 109*e4b17023SJohn Marino * @param __from_end End of input. 110*e4b17023SJohn Marino * @param __from_next Returns start of unconverted data. 111*e4b17023SJohn Marino * @param __to Start of output buffer. 112*e4b17023SJohn Marino * @param __to_end End of output buffer. 113*e4b17023SJohn Marino * @param __to_next Returns start of unused output area. 114*e4b17023SJohn Marino * @return codecvt_base::result. 115*e4b17023SJohn Marino */ 116*e4b17023SJohn Marino result 117*e4b17023SJohn Marino out(state_type& __state, const intern_type* __from, 118*e4b17023SJohn Marino const intern_type* __from_end, const intern_type*& __from_next, 119*e4b17023SJohn Marino extern_type* __to, extern_type* __to_end, 120*e4b17023SJohn Marino extern_type*& __to_next) const 121*e4b17023SJohn Marino { 122*e4b17023SJohn Marino return this->do_out(__state, __from, __from_end, __from_next, 123*e4b17023SJohn Marino __to, __to_end, __to_next); 124*e4b17023SJohn Marino } 125*e4b17023SJohn Marino 126*e4b17023SJohn Marino /** 127*e4b17023SJohn Marino * @brief Reset conversion state. 128*e4b17023SJohn Marino * 129*e4b17023SJohn Marino * Writes characters to output that would restore @a state to initial 130*e4b17023SJohn Marino * conditions. The idea is that if a partial conversion occurs, then 131*e4b17023SJohn Marino * the converting the characters written by this function would leave 132*e4b17023SJohn Marino * the state in initial conditions, rather than partial conversion 133*e4b17023SJohn Marino * state. It does this by calling codecvt::do_unshift(). 134*e4b17023SJohn Marino * 135*e4b17023SJohn Marino * For example, if 4 external characters always converted to 1 internal 136*e4b17023SJohn Marino * character, and input to in() had 6 external characters with state 137*e4b17023SJohn Marino * saved, this function would write two characters to the output and 138*e4b17023SJohn Marino * set the state to initialized conditions. 139*e4b17023SJohn Marino * 140*e4b17023SJohn Marino * The source and destination character sets are determined by the 141*e4b17023SJohn Marino * facet's locale, internal and external types. 142*e4b17023SJohn Marino * 143*e4b17023SJohn Marino * The result returned is a member of codecvt_base::result. If the 144*e4b17023SJohn Marino * state could be reset and data written, returns codecvt_base::ok. If 145*e4b17023SJohn Marino * no conversion is necessary, returns codecvt_base::noconv. If the 146*e4b17023SJohn Marino * output has insufficient space, returns codecvt_base::partial. 147*e4b17023SJohn Marino * Otherwise the reset failed and codecvt_base::error is returned. 148*e4b17023SJohn Marino * 149*e4b17023SJohn Marino * @param __state Persistent conversion state data. 150*e4b17023SJohn Marino * @param __to Start of output buffer. 151*e4b17023SJohn Marino * @param __to_end End of output buffer. 152*e4b17023SJohn Marino * @param __to_next Returns start of unused output area. 153*e4b17023SJohn Marino * @return codecvt_base::result. 154*e4b17023SJohn Marino */ 155*e4b17023SJohn Marino result 156*e4b17023SJohn Marino unshift(state_type& __state, extern_type* __to, extern_type* __to_end, 157*e4b17023SJohn Marino extern_type*& __to_next) const 158*e4b17023SJohn Marino { return this->do_unshift(__state, __to,__to_end,__to_next); } 159*e4b17023SJohn Marino 160*e4b17023SJohn Marino /** 161*e4b17023SJohn Marino * @brief Convert from external to internal character set. 162*e4b17023SJohn Marino * 163*e4b17023SJohn Marino * Converts input string of extern_type to output string of 164*e4b17023SJohn Marino * intern_type. This is analogous to mbsrtowcs. It does this by 165*e4b17023SJohn Marino * calling codecvt::do_in. 166*e4b17023SJohn Marino * 167*e4b17023SJohn Marino * The source and destination character sets are determined by the 168*e4b17023SJohn Marino * facet's locale, internal and external types. 169*e4b17023SJohn Marino * 170*e4b17023SJohn Marino * The characters in [from,from_end) are converted and written to 171*e4b17023SJohn Marino * [to,to_end). from_next and to_next are set to point to the 172*e4b17023SJohn Marino * character following the last successfully converted character, 173*e4b17023SJohn Marino * respectively. If the result needed no conversion, from_next and 174*e4b17023SJohn Marino * to_next are not affected. 175*e4b17023SJohn Marino * 176*e4b17023SJohn Marino * The @a state argument should be initialized if the input is at the 177*e4b17023SJohn Marino * beginning and carried from a previous call if continuing 178*e4b17023SJohn Marino * conversion. There are no guarantees about how @a state is used. 179*e4b17023SJohn Marino * 180*e4b17023SJohn Marino * The result returned is a member of codecvt_base::result. If 181*e4b17023SJohn Marino * all the input is converted, returns codecvt_base::ok. If no 182*e4b17023SJohn Marino * conversion is necessary, returns codecvt_base::noconv. If 183*e4b17023SJohn Marino * the input ends early or there is insufficient space in the 184*e4b17023SJohn Marino * output, returns codecvt_base::partial. Otherwise the 185*e4b17023SJohn Marino * conversion failed and codecvt_base::error is returned. 186*e4b17023SJohn Marino * 187*e4b17023SJohn Marino * @param __state Persistent conversion state data. 188*e4b17023SJohn Marino * @param __from Start of input. 189*e4b17023SJohn Marino * @param __from_end End of input. 190*e4b17023SJohn Marino * @param __from_next Returns start of unconverted data. 191*e4b17023SJohn Marino * @param __to Start of output buffer. 192*e4b17023SJohn Marino * @param __to_end End of output buffer. 193*e4b17023SJohn Marino * @param __to_next Returns start of unused output area. 194*e4b17023SJohn Marino * @return codecvt_base::result. 195*e4b17023SJohn Marino */ 196*e4b17023SJohn Marino result 197*e4b17023SJohn Marino in(state_type& __state, const extern_type* __from, 198*e4b17023SJohn Marino const extern_type* __from_end, const extern_type*& __from_next, 199*e4b17023SJohn Marino intern_type* __to, intern_type* __to_end, 200*e4b17023SJohn Marino intern_type*& __to_next) const 201*e4b17023SJohn Marino { 202*e4b17023SJohn Marino return this->do_in(__state, __from, __from_end, __from_next, 203*e4b17023SJohn Marino __to, __to_end, __to_next); 204*e4b17023SJohn Marino } 205*e4b17023SJohn Marino 206*e4b17023SJohn Marino int 207*e4b17023SJohn Marino encoding() const throw() 208*e4b17023SJohn Marino { return this->do_encoding(); } 209*e4b17023SJohn Marino 210*e4b17023SJohn Marino bool 211*e4b17023SJohn Marino always_noconv() const throw() 212*e4b17023SJohn Marino { return this->do_always_noconv(); } 213*e4b17023SJohn Marino 214*e4b17023SJohn Marino int 215*e4b17023SJohn Marino length(state_type& __state, const extern_type* __from, 216*e4b17023SJohn Marino const extern_type* __end, size_t __max) const 217*e4b17023SJohn Marino { return this->do_length(__state, __from, __end, __max); } 218*e4b17023SJohn Marino 219*e4b17023SJohn Marino int 220*e4b17023SJohn Marino max_length() const throw() 221*e4b17023SJohn Marino { return this->do_max_length(); } 222*e4b17023SJohn Marino 223*e4b17023SJohn Marino protected: 224*e4b17023SJohn Marino explicit 225*e4b17023SJohn Marino __codecvt_abstract_base(size_t __refs = 0) : locale::facet(__refs) { } 226*e4b17023SJohn Marino 227*e4b17023SJohn Marino virtual 228*e4b17023SJohn Marino ~__codecvt_abstract_base() { } 229*e4b17023SJohn Marino 230*e4b17023SJohn Marino /** 231*e4b17023SJohn Marino * @brief Convert from internal to external character set. 232*e4b17023SJohn Marino * 233*e4b17023SJohn Marino * Converts input string of intern_type to output string of 234*e4b17023SJohn Marino * extern_type. This function is a hook for derived classes to change 235*e4b17023SJohn Marino * the value returned. @see out for more information. 236*e4b17023SJohn Marino */ 237*e4b17023SJohn Marino virtual result 238*e4b17023SJohn Marino do_out(state_type& __state, const intern_type* __from, 239*e4b17023SJohn Marino const intern_type* __from_end, const intern_type*& __from_next, 240*e4b17023SJohn Marino extern_type* __to, extern_type* __to_end, 241*e4b17023SJohn Marino extern_type*& __to_next) const = 0; 242*e4b17023SJohn Marino 243*e4b17023SJohn Marino virtual result 244*e4b17023SJohn Marino do_unshift(state_type& __state, extern_type* __to, 245*e4b17023SJohn Marino extern_type* __to_end, extern_type*& __to_next) const = 0; 246*e4b17023SJohn Marino 247*e4b17023SJohn Marino virtual result 248*e4b17023SJohn Marino do_in(state_type& __state, const extern_type* __from, 249*e4b17023SJohn Marino const extern_type* __from_end, const extern_type*& __from_next, 250*e4b17023SJohn Marino intern_type* __to, intern_type* __to_end, 251*e4b17023SJohn Marino intern_type*& __to_next) const = 0; 252*e4b17023SJohn Marino 253*e4b17023SJohn Marino virtual int 254*e4b17023SJohn Marino do_encoding() const throw() = 0; 255*e4b17023SJohn Marino 256*e4b17023SJohn Marino virtual bool 257*e4b17023SJohn Marino do_always_noconv() const throw() = 0; 258*e4b17023SJohn Marino 259*e4b17023SJohn Marino virtual int 260*e4b17023SJohn Marino do_length(state_type&, const extern_type* __from, 261*e4b17023SJohn Marino const extern_type* __end, size_t __max) const = 0; 262*e4b17023SJohn Marino 263*e4b17023SJohn Marino virtual int 264*e4b17023SJohn Marino do_max_length() const throw() = 0; 265*e4b17023SJohn Marino }; 266*e4b17023SJohn Marino 267*e4b17023SJohn Marino 268*e4b17023SJohn Marino 269*e4b17023SJohn Marino /** 270*e4b17023SJohn Marino * @brief Primary class template codecvt. 271*e4b17023SJohn Marino * @ingroup locales 272*e4b17023SJohn Marino * 273*e4b17023SJohn Marino * NB: Generic, mostly useless implementation. 274*e4b17023SJohn Marino * 275*e4b17023SJohn Marino */ 276*e4b17023SJohn Marino template<typename _InternT, typename _ExternT, typename _StateT> 277*e4b17023SJohn Marino class codecvt 278*e4b17023SJohn Marino : public __codecvt_abstract_base<_InternT, _ExternT, _StateT> 279*e4b17023SJohn Marino { 280*e4b17023SJohn Marino public: 281*e4b17023SJohn Marino // Types: 282*e4b17023SJohn Marino typedef codecvt_base::result result; 283*e4b17023SJohn Marino typedef _InternT intern_type; 284*e4b17023SJohn Marino typedef _ExternT extern_type; 285*e4b17023SJohn Marino typedef _StateT state_type; 286*e4b17023SJohn Marino 287*e4b17023SJohn Marino protected: 288*e4b17023SJohn Marino __c_locale _M_c_locale_codecvt; 289*e4b17023SJohn Marino 290*e4b17023SJohn Marino public: 291*e4b17023SJohn Marino static locale::id id; 292*e4b17023SJohn Marino 293*e4b17023SJohn Marino explicit 294*e4b17023SJohn Marino codecvt(size_t __refs = 0) 295*e4b17023SJohn Marino : __codecvt_abstract_base<_InternT, _ExternT, _StateT> (__refs), 296*e4b17023SJohn Marino _M_c_locale_codecvt(0) 297*e4b17023SJohn Marino { } 298*e4b17023SJohn Marino 299*e4b17023SJohn Marino explicit 300*e4b17023SJohn Marino codecvt(__c_locale __cloc, size_t __refs = 0); 301*e4b17023SJohn Marino 302*e4b17023SJohn Marino protected: 303*e4b17023SJohn Marino virtual 304*e4b17023SJohn Marino ~codecvt() { } 305*e4b17023SJohn Marino 306*e4b17023SJohn Marino virtual result 307*e4b17023SJohn Marino do_out(state_type& __state, const intern_type* __from, 308*e4b17023SJohn Marino const intern_type* __from_end, const intern_type*& __from_next, 309*e4b17023SJohn Marino extern_type* __to, extern_type* __to_end, 310*e4b17023SJohn Marino extern_type*& __to_next) const; 311*e4b17023SJohn Marino 312*e4b17023SJohn Marino virtual result 313*e4b17023SJohn Marino do_unshift(state_type& __state, extern_type* __to, 314*e4b17023SJohn Marino extern_type* __to_end, extern_type*& __to_next) const; 315*e4b17023SJohn Marino 316*e4b17023SJohn Marino virtual result 317*e4b17023SJohn Marino do_in(state_type& __state, const extern_type* __from, 318*e4b17023SJohn Marino const extern_type* __from_end, const extern_type*& __from_next, 319*e4b17023SJohn Marino intern_type* __to, intern_type* __to_end, 320*e4b17023SJohn Marino intern_type*& __to_next) const; 321*e4b17023SJohn Marino 322*e4b17023SJohn Marino virtual int 323*e4b17023SJohn Marino do_encoding() const throw(); 324*e4b17023SJohn Marino 325*e4b17023SJohn Marino virtual bool 326*e4b17023SJohn Marino do_always_noconv() const throw(); 327*e4b17023SJohn Marino 328*e4b17023SJohn Marino virtual int 329*e4b17023SJohn Marino do_length(state_type&, const extern_type* __from, 330*e4b17023SJohn Marino const extern_type* __end, size_t __max) const; 331*e4b17023SJohn Marino 332*e4b17023SJohn Marino virtual int 333*e4b17023SJohn Marino do_max_length() const throw(); 334*e4b17023SJohn Marino }; 335*e4b17023SJohn Marino 336*e4b17023SJohn Marino template<typename _InternT, typename _ExternT, typename _StateT> 337*e4b17023SJohn Marino locale::id codecvt<_InternT, _ExternT, _StateT>::id; 338*e4b17023SJohn Marino 339*e4b17023SJohn Marino /// class codecvt<char, char, mbstate_t> specialization. 340*e4b17023SJohn Marino template<> 341*e4b17023SJohn Marino class codecvt<char, char, mbstate_t> 342*e4b17023SJohn Marino : public __codecvt_abstract_base<char, char, mbstate_t> 343*e4b17023SJohn Marino { 344*e4b17023SJohn Marino public: 345*e4b17023SJohn Marino // Types: 346*e4b17023SJohn Marino typedef char intern_type; 347*e4b17023SJohn Marino typedef char extern_type; 348*e4b17023SJohn Marino typedef mbstate_t state_type; 349*e4b17023SJohn Marino 350*e4b17023SJohn Marino protected: 351*e4b17023SJohn Marino __c_locale _M_c_locale_codecvt; 352*e4b17023SJohn Marino 353*e4b17023SJohn Marino public: 354*e4b17023SJohn Marino static locale::id id; 355*e4b17023SJohn Marino 356*e4b17023SJohn Marino explicit 357*e4b17023SJohn Marino codecvt(size_t __refs = 0); 358*e4b17023SJohn Marino 359*e4b17023SJohn Marino explicit 360*e4b17023SJohn Marino codecvt(__c_locale __cloc, size_t __refs = 0); 361*e4b17023SJohn Marino 362*e4b17023SJohn Marino protected: 363*e4b17023SJohn Marino virtual 364*e4b17023SJohn Marino ~codecvt(); 365*e4b17023SJohn Marino 366*e4b17023SJohn Marino virtual result 367*e4b17023SJohn Marino do_out(state_type& __state, const intern_type* __from, 368*e4b17023SJohn Marino const intern_type* __from_end, const intern_type*& __from_next, 369*e4b17023SJohn Marino extern_type* __to, extern_type* __to_end, 370*e4b17023SJohn Marino extern_type*& __to_next) const; 371*e4b17023SJohn Marino 372*e4b17023SJohn Marino virtual result 373*e4b17023SJohn Marino do_unshift(state_type& __state, extern_type* __to, 374*e4b17023SJohn Marino extern_type* __to_end, extern_type*& __to_next) const; 375*e4b17023SJohn Marino 376*e4b17023SJohn Marino virtual result 377*e4b17023SJohn Marino do_in(state_type& __state, const extern_type* __from, 378*e4b17023SJohn Marino const extern_type* __from_end, const extern_type*& __from_next, 379*e4b17023SJohn Marino intern_type* __to, intern_type* __to_end, 380*e4b17023SJohn Marino intern_type*& __to_next) const; 381*e4b17023SJohn Marino 382*e4b17023SJohn Marino virtual int 383*e4b17023SJohn Marino do_encoding() const throw(); 384*e4b17023SJohn Marino 385*e4b17023SJohn Marino virtual bool 386*e4b17023SJohn Marino do_always_noconv() const throw(); 387*e4b17023SJohn Marino 388*e4b17023SJohn Marino virtual int 389*e4b17023SJohn Marino do_length(state_type&, const extern_type* __from, 390*e4b17023SJohn Marino const extern_type* __end, size_t __max) const; 391*e4b17023SJohn Marino 392*e4b17023SJohn Marino virtual int 393*e4b17023SJohn Marino do_max_length() const throw(); 394*e4b17023SJohn Marino }; 395*e4b17023SJohn Marino 396*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T 397*e4b17023SJohn Marino /// class codecvt<wchar_t, char, mbstate_t> specialization. 398*e4b17023SJohn Marino template<> 399*e4b17023SJohn Marino class codecvt<wchar_t, char, mbstate_t> 400*e4b17023SJohn Marino : public __codecvt_abstract_base<wchar_t, char, mbstate_t> 401*e4b17023SJohn Marino { 402*e4b17023SJohn Marino public: 403*e4b17023SJohn Marino // Types: 404*e4b17023SJohn Marino typedef wchar_t intern_type; 405*e4b17023SJohn Marino typedef char extern_type; 406*e4b17023SJohn Marino typedef mbstate_t state_type; 407*e4b17023SJohn Marino 408*e4b17023SJohn Marino protected: 409*e4b17023SJohn Marino __c_locale _M_c_locale_codecvt; 410*e4b17023SJohn Marino 411*e4b17023SJohn Marino public: 412*e4b17023SJohn Marino static locale::id id; 413*e4b17023SJohn Marino 414*e4b17023SJohn Marino explicit 415*e4b17023SJohn Marino codecvt(size_t __refs = 0); 416*e4b17023SJohn Marino 417*e4b17023SJohn Marino explicit 418*e4b17023SJohn Marino codecvt(__c_locale __cloc, size_t __refs = 0); 419*e4b17023SJohn Marino 420*e4b17023SJohn Marino protected: 421*e4b17023SJohn Marino virtual 422*e4b17023SJohn Marino ~codecvt(); 423*e4b17023SJohn Marino 424*e4b17023SJohn Marino virtual result 425*e4b17023SJohn Marino do_out(state_type& __state, const intern_type* __from, 426*e4b17023SJohn Marino const intern_type* __from_end, const intern_type*& __from_next, 427*e4b17023SJohn Marino extern_type* __to, extern_type* __to_end, 428*e4b17023SJohn Marino extern_type*& __to_next) const; 429*e4b17023SJohn Marino 430*e4b17023SJohn Marino virtual result 431*e4b17023SJohn Marino do_unshift(state_type& __state, 432*e4b17023SJohn Marino extern_type* __to, extern_type* __to_end, 433*e4b17023SJohn Marino extern_type*& __to_next) const; 434*e4b17023SJohn Marino 435*e4b17023SJohn Marino virtual result 436*e4b17023SJohn Marino do_in(state_type& __state, 437*e4b17023SJohn Marino const extern_type* __from, const extern_type* __from_end, 438*e4b17023SJohn Marino const extern_type*& __from_next, 439*e4b17023SJohn Marino intern_type* __to, intern_type* __to_end, 440*e4b17023SJohn Marino intern_type*& __to_next) const; 441*e4b17023SJohn Marino 442*e4b17023SJohn Marino virtual 443*e4b17023SJohn Marino int do_encoding() const throw(); 444*e4b17023SJohn Marino 445*e4b17023SJohn Marino virtual 446*e4b17023SJohn Marino bool do_always_noconv() const throw(); 447*e4b17023SJohn Marino 448*e4b17023SJohn Marino virtual 449*e4b17023SJohn Marino int do_length(state_type&, const extern_type* __from, 450*e4b17023SJohn Marino const extern_type* __end, size_t __max) const; 451*e4b17023SJohn Marino 452*e4b17023SJohn Marino virtual int 453*e4b17023SJohn Marino do_max_length() const throw(); 454*e4b17023SJohn Marino }; 455*e4b17023SJohn Marino #endif //_GLIBCXX_USE_WCHAR_T 456*e4b17023SJohn Marino 457*e4b17023SJohn Marino /// class codecvt_byname [22.2.1.6]. 458*e4b17023SJohn Marino template<typename _InternT, typename _ExternT, typename _StateT> 459*e4b17023SJohn Marino class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> 460*e4b17023SJohn Marino { 461*e4b17023SJohn Marino public: 462*e4b17023SJohn Marino explicit 463*e4b17023SJohn Marino codecvt_byname(const char* __s, size_t __refs = 0) 464*e4b17023SJohn Marino : codecvt<_InternT, _ExternT, _StateT>(__refs) 465*e4b17023SJohn Marino { 466*e4b17023SJohn Marino if (__builtin_strcmp(__s, "C") != 0 467*e4b17023SJohn Marino && __builtin_strcmp(__s, "POSIX") != 0) 468*e4b17023SJohn Marino { 469*e4b17023SJohn Marino this->_S_destroy_c_locale(this->_M_c_locale_codecvt); 470*e4b17023SJohn Marino this->_S_create_c_locale(this->_M_c_locale_codecvt, __s); 471*e4b17023SJohn Marino } 472*e4b17023SJohn Marino } 473*e4b17023SJohn Marino 474*e4b17023SJohn Marino protected: 475*e4b17023SJohn Marino virtual 476*e4b17023SJohn Marino ~codecvt_byname() { } 477*e4b17023SJohn Marino }; 478*e4b17023SJohn Marino 479*e4b17023SJohn Marino // Inhibit implicit instantiations for required instantiations, 480*e4b17023SJohn Marino // which are defined via explicit instantiations elsewhere. 481*e4b17023SJohn Marino #if _GLIBCXX_EXTERN_TEMPLATE 482*e4b17023SJohn Marino extern template class codecvt_byname<char, char, mbstate_t>; 483*e4b17023SJohn Marino 484*e4b17023SJohn Marino extern template 485*e4b17023SJohn Marino const codecvt<char, char, mbstate_t>& 486*e4b17023SJohn Marino use_facet<codecvt<char, char, mbstate_t> >(const locale&); 487*e4b17023SJohn Marino 488*e4b17023SJohn Marino extern template 489*e4b17023SJohn Marino bool 490*e4b17023SJohn Marino has_facet<codecvt<char, char, mbstate_t> >(const locale&); 491*e4b17023SJohn Marino 492*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T 493*e4b17023SJohn Marino extern template class codecvt_byname<wchar_t, char, mbstate_t>; 494*e4b17023SJohn Marino 495*e4b17023SJohn Marino extern template 496*e4b17023SJohn Marino const codecvt<wchar_t, char, mbstate_t>& 497*e4b17023SJohn Marino use_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&); 498*e4b17023SJohn Marino 499*e4b17023SJohn Marino extern template 500*e4b17023SJohn Marino bool 501*e4b17023SJohn Marino has_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&); 502*e4b17023SJohn Marino #endif 503*e4b17023SJohn Marino #endif 504*e4b17023SJohn Marino 505*e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_VERSION 506*e4b17023SJohn Marino } // namespace std 507*e4b17023SJohn Marino 508*e4b17023SJohn Marino #endif // _CODECVT_H 509