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