35 #ifndef _EXT_CODECVT_SPECIALIZATIONS_H 36 #define _EXT_CODECVT_SPECIALIZATIONS_H 1 44 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
46 _GLIBCXX_BEGIN_NAMESPACE_VERSION
47 _GLIBCXX_BEGIN_NAMESPACE_CXX11
59 typedef iconv_t descriptor_type;
69 descriptor_type _M_in_desc;
72 descriptor_type _M_out_desc;
88 : _M_in_desc(0), _M_out_desc(0), _M_ext_bom(0), _M_int_bom(0), _M_bytes(0)
93 int __ibom = 0,
int __ebom = 0,
int __bytes = 1)
94 : _M_int_enc(__int), _M_ext_enc(__ext), _M_in_desc(0), _M_out_desc(0),
95 _M_ext_bom(__ebom), _M_int_bom(__ibom), _M_bytes(__bytes)
107 { construct(__obj); }
123 const descriptor_type __err = (iconv_t)(-1);
124 bool __test = _M_in_desc && _M_in_desc != __err;
125 __test &= _M_out_desc && _M_out_desc != __err;
130 character_ratio()
const 134 internal_encoding()
const 135 {
return _M_int_enc; }
139 {
return _M_int_bom; }
142 external_encoding()
const 143 {
return _M_ext_enc; }
147 {
return _M_ext_bom; }
149 const descriptor_type&
150 in_descriptor()
const 151 {
return _M_in_desc; }
153 const descriptor_type&
154 out_descriptor()
const 155 {
return _M_out_desc; }
161 const descriptor_type __err = (iconv_t)(-1);
162 const bool __have_encodings = _M_int_enc.
size() && _M_ext_enc.
size();
163 if (!_M_in_desc && __have_encodings)
165 _M_in_desc = iconv_open(_M_int_enc.
c_str(), _M_ext_enc.
c_str());
166 if (_M_in_desc == __err)
167 std::__throw_runtime_error(__N(
"encoding_state::_M_init " 168 "creating iconv input descriptor failed"));
170 if (!_M_out_desc && __have_encodings)
172 _M_out_desc = iconv_open(_M_ext_enc.
c_str(), _M_int_enc.
c_str());
173 if (_M_out_desc == __err)
174 std::__throw_runtime_error(__N(
"encoding_state::_M_init " 175 "creating iconv output descriptor failed"));
183 _M_int_enc = __obj._M_int_enc;
184 _M_ext_enc = __obj._M_ext_enc;
185 _M_ext_bom = __obj._M_ext_bom;
186 _M_int_bom = __obj._M_int_bom;
187 _M_bytes = __obj._M_bytes;
194 const descriptor_type __err = (iconv_t)(-1);
195 if (_M_in_desc && _M_in_desc != __err)
197 iconv_close(_M_in_desc);
200 if (_M_out_desc && _M_out_desc != __err)
202 iconv_close(_M_out_desc);
212 template<
typename _CharT>
220 _GLIBCXX_END_NAMESPACE_CXX11
221 _GLIBCXX_END_NAMESPACE_VERSION
225 namespace std _GLIBCXX_VISIBILITY(default)
227 _GLIBCXX_BEGIN_NAMESPACE_VERSION
234 template<
typename _InternT,
typename _ExternT>
240 typedef codecvt_base::result result;
241 typedef _InternT intern_type;
242 typedef _ExternT extern_type;
244 typedef state_type::descriptor_type descriptor_type;
265 const intern_type* __from_end,
const intern_type*& __from_next,
266 extern_type* __to, extern_type* __to_end,
267 extern_type*& __to_next)
const;
270 do_unshift(
state_type& __state, extern_type* __to,
271 extern_type* __to_end, extern_type*& __to_next)
const;
274 do_in(
state_type& __state,
const extern_type* __from,
275 const extern_type* __from_end,
const extern_type*& __from_next,
276 intern_type* __to, intern_type* __to_end,
277 intern_type*& __to_next)
const;
280 do_encoding()
const throw();
283 do_always_noconv()
const throw();
286 do_length(
state_type&,
const extern_type* __from,
287 const extern_type* __end,
size_t __max)
const;
290 do_max_length()
const throw();
293 template<
typename _InternT,
typename _ExternT>
301 template<
typename _Tp>
303 __iconv_adaptor(
size_t(*__func)(iconv_t, _Tp,
size_t*,
char**,
size_t*),
304 iconv_t __cd,
char** __inbuf,
size_t* __inbytes,
305 char** __outbuf,
size_t* __outbytes)
306 {
return __func(__cd, (_Tp)__inbuf, __inbytes, __outbuf, __outbytes); }
308 template<
typename _InternT,
typename _ExternT>
312 const intern_type* __from_end,
const intern_type*& __from_next,
313 extern_type* __to, extern_type* __to_end,
314 extern_type*& __to_next)
const 316 result __ret = codecvt_base::error;
319 const descriptor_type& __desc = __state.out_descriptor();
320 const size_t __fmultiple =
sizeof(intern_type);
321 size_t __fbytes = __fmultiple * (__from_end - __from);
322 const size_t __tmultiple =
sizeof(extern_type);
323 size_t __tbytes = __tmultiple * (__to_end - __to);
327 char* __cto =
reinterpret_cast<char*
>(__to);
336 int __int_bom = __state.internal_bom();
339 size_t __size = __from_end - __from;
340 intern_type* __cfixed =
static_cast<intern_type*
> 341 (__builtin_alloca(
sizeof(intern_type) * (__size + 1)));
342 __cfixed[0] =
static_cast<intern_type
>(__int_bom);
344 __cfrom =
reinterpret_cast<char*
>(__cfixed);
345 __conv = __iconv_adaptor(iconv, __desc, &__cfrom,
346 &__fbytes, &__cto, &__tbytes);
350 intern_type* __cfixed =
const_cast<intern_type*
>(__from);
351 __cfrom =
reinterpret_cast<char*
>(__cfixed);
352 __conv = __iconv_adaptor(iconv, __desc, &__cfrom, &__fbytes,
356 if (__conv !=
size_t(-1))
358 __from_next =
reinterpret_cast<const intern_type*
>(__cfrom);
359 __to_next =
reinterpret_cast<extern_type*
>(__cto);
360 __ret = codecvt_base::ok;
364 if (__fbytes < __fmultiple * (__from_end - __from))
366 __from_next =
reinterpret_cast<const intern_type*
>(__cfrom);
367 __to_next =
reinterpret_cast<extern_type*
>(__cto);
368 __ret = codecvt_base::partial;
371 __ret = codecvt_base::error;
377 template<
typename _InternT,
typename _ExternT>
380 do_unshift(state_type& __state, extern_type* __to,
381 extern_type* __to_end, extern_type*& __to_next)
const 383 result __ret = codecvt_base::error;
386 const descriptor_type& __desc = __state.in_descriptor();
387 const size_t __tmultiple =
sizeof(intern_type);
388 size_t __tlen = __tmultiple * (__to_end - __to);
392 char* __cto =
reinterpret_cast<char*
>(__to);
393 size_t __conv = __iconv_adaptor(iconv,__desc, 0, 0,
396 if (__conv !=
size_t(-1))
398 __to_next =
reinterpret_cast<extern_type*
>(__cto);
399 if (__tlen == __tmultiple * (__to_end - __to))
400 __ret = codecvt_base::noconv;
401 else if (__tlen == 0)
402 __ret = codecvt_base::ok;
404 __ret = codecvt_base::partial;
407 __ret = codecvt_base::error;
412 template<
typename _InternT,
typename _ExternT>
414 codecvt<_InternT, _ExternT, encoding_state>::
415 do_in(state_type& __state,
const extern_type* __from,
416 const extern_type* __from_end,
const extern_type*& __from_next,
417 intern_type* __to, intern_type* __to_end,
418 intern_type*& __to_next)
const 420 result __ret = codecvt_base::error;
423 const descriptor_type& __desc = __state.in_descriptor();
424 const size_t __fmultiple =
sizeof(extern_type);
425 size_t __flen = __fmultiple * (__from_end - __from);
426 const size_t __tmultiple =
sizeof(intern_type);
427 size_t __tlen = __tmultiple * (__to_end - __to);
431 char* __cto =
reinterpret_cast<char*
>(__to);
440 int __ext_bom = __state.external_bom();
443 size_t __size = __from_end - __from;
444 extern_type* __cfixed =
static_cast<extern_type*
> 445 (__builtin_alloca(
sizeof(extern_type) * (__size + 1)));
446 __cfixed[0] =
static_cast<extern_type
>(__ext_bom);
447 char_traits<extern_type>::copy(__cfixed + 1, __from, __size);
448 __cfrom =
reinterpret_cast<char*
>(__cfixed);
449 __conv = __iconv_adaptor(iconv, __desc, &__cfrom,
450 &__flen, &__cto, &__tlen);
454 extern_type* __cfixed =
const_cast<extern_type*
>(__from);
455 __cfrom =
reinterpret_cast<char*
>(__cfixed);
456 __conv = __iconv_adaptor(iconv, __desc, &__cfrom,
457 &__flen, &__cto, &__tlen);
461 if (__conv !=
size_t(-1))
463 __from_next =
reinterpret_cast<const extern_type*
>(__cfrom);
464 __to_next =
reinterpret_cast<intern_type*
>(__cto);
465 __ret = codecvt_base::ok;
469 if (__flen < static_cast<size_t>(__from_end - __from))
471 __from_next =
reinterpret_cast<const extern_type*
>(__cfrom);
472 __to_next =
reinterpret_cast<intern_type*
>(__cto);
473 __ret = codecvt_base::partial;
476 __ret = codecvt_base::error;
482 template<
typename _InternT,
typename _ExternT>
484 codecvt<_InternT, _ExternT, encoding_state>::
485 do_encoding()
const throw()
488 if (
sizeof(_ExternT) <=
sizeof(_InternT))
489 __ret =
sizeof(_InternT) /
sizeof(_ExternT);
493 template<
typename _InternT,
typename _ExternT>
495 codecvt<_InternT, _ExternT, encoding_state>::
496 do_always_noconv()
const throw()
499 template<
typename _InternT,
typename _ExternT>
501 codecvt<_InternT, _ExternT, encoding_state>::
502 do_length(state_type&,
const extern_type* __from,
503 const extern_type* __end,
size_t __max)
const 504 {
return std::min(__max, static_cast<size_t>(__end - __from)); }
508 template<
typename _InternT,
typename _ExternT>
510 codecvt<_InternT, _ExternT, encoding_state>::
511 do_max_length()
const throw()
514 _GLIBCXX_END_NAMESPACE_VERSION
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
virtual result do_out(state_type &__state, const intern_type *__from, const intern_type *__from_end, const intern_type *&__from_next, extern_type *__to, extern_type *__to_end, extern_type *&__to_next) const
Convert from internal to external character set.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
Primary class template codecvt.NB: Generic, mostly useless implementation.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
GNU extensions for public use.
Class representing stream positions.
Common base for codecvt functions.
ISO C++ entities toplevel namespace is std.
Facet ID class.The ID class provides facets with an index used to identify them. Every facet class mu...
Extension to use iconv for dealing with character encodings.
Basis for explicit traits specializations.