35 #ifndef _EXT_CODECVT_SPECIALIZATIONS_H 36 #define _EXT_CODECVT_SPECIALIZATIONS_H 1 42 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
44 _GLIBCXX_BEGIN_NAMESPACE_VERSION
45 _GLIBCXX_BEGIN_NAMESPACE_CXX11
57 typedef iconv_t descriptor_type;
67 descriptor_type _M_in_desc;
70 descriptor_type _M_out_desc;
86 : _M_in_desc(0), _M_out_desc(0), _M_ext_bom(0), _M_int_bom(0), _M_bytes(0)
91 int __ibom = 0,
int __ebom = 0,
int __bytes = 1)
92 : _M_int_enc(__int), _M_ext_enc(__ext), _M_in_desc(0), _M_out_desc(0),
93 _M_ext_bom(__ebom), _M_int_bom(__ibom), _M_bytes(__bytes)
105 { construct(__obj); }
121 const descriptor_type __err = (iconv_t)(-1);
122 bool __test = _M_in_desc && _M_in_desc != __err;
123 __test &= _M_out_desc && _M_out_desc != __err;
128 character_ratio()
const 132 internal_encoding()
const 133 {
return _M_int_enc; }
137 {
return _M_int_bom; }
140 external_encoding()
const 141 {
return _M_ext_enc; }
145 {
return _M_ext_bom; }
147 const descriptor_type&
148 in_descriptor()
const 149 {
return _M_in_desc; }
151 const descriptor_type&
152 out_descriptor()
const 153 {
return _M_out_desc; }
159 const descriptor_type __err = (iconv_t)(-1);
160 const bool __have_encodings = _M_int_enc.
size() && _M_ext_enc.
size();
161 if (!_M_in_desc && __have_encodings)
163 _M_in_desc = iconv_open(_M_int_enc.
c_str(), _M_ext_enc.
c_str());
164 if (_M_in_desc == __err)
165 std::__throw_runtime_error(__N(
"encoding_state::_M_init " 166 "creating iconv input descriptor failed"));
168 if (!_M_out_desc && __have_encodings)
170 _M_out_desc = iconv_open(_M_ext_enc.
c_str(), _M_int_enc.
c_str());
171 if (_M_out_desc == __err)
172 std::__throw_runtime_error(__N(
"encoding_state::_M_init " 173 "creating iconv output descriptor failed"));
181 _M_int_enc = __obj._M_int_enc;
182 _M_ext_enc = __obj._M_ext_enc;
183 _M_ext_bom = __obj._M_ext_bom;
184 _M_int_bom = __obj._M_int_bom;
185 _M_bytes = __obj._M_bytes;
192 const descriptor_type __err = (iconv_t)(-1);
193 if (_M_in_desc && _M_in_desc != __err)
195 iconv_close(_M_in_desc);
198 if (_M_out_desc && _M_out_desc != __err)
200 iconv_close(_M_out_desc);
210 template<
typename _CharT>
218 _GLIBCXX_END_NAMESPACE_CXX11
219 _GLIBCXX_END_NAMESPACE_VERSION
223 namespace std _GLIBCXX_VISIBILITY(default)
225 _GLIBCXX_BEGIN_NAMESPACE_VERSION
232 template<
typename _InternT,
typename _ExternT>
238 typedef codecvt_base::result result;
239 typedef _InternT intern_type;
240 typedef _ExternT extern_type;
242 typedef state_type::descriptor_type descriptor_type;
263 const intern_type* __from_end,
const intern_type*& __from_next,
264 extern_type* __to, extern_type* __to_end,
265 extern_type*& __to_next)
const;
268 do_unshift(
state_type& __state, extern_type* __to,
269 extern_type* __to_end, extern_type*& __to_next)
const;
272 do_in(
state_type& __state,
const extern_type* __from,
273 const extern_type* __from_end,
const extern_type*& __from_next,
274 intern_type* __to, intern_type* __to_end,
275 intern_type*& __to_next)
const;
278 do_encoding()
const throw();
281 do_always_noconv()
const throw();
284 do_length(
state_type&,
const extern_type* __from,
285 const extern_type* __end,
size_t __max)
const;
288 do_max_length()
const throw();
291 template<
typename _InternT,
typename _ExternT>
299 template<
typename _Tp>
301 __iconv_adaptor(
size_t(*__func)(iconv_t, _Tp,
size_t*,
char**,
size_t*),
302 iconv_t __cd,
char** __inbuf,
size_t* __inbytes,
303 char** __outbuf,
size_t* __outbytes)
304 {
return __func(__cd, (_Tp)__inbuf, __inbytes, __outbuf, __outbytes); }
306 template<
typename _InternT,
typename _ExternT>
310 const intern_type* __from_end,
const intern_type*& __from_next,
311 extern_type* __to, extern_type* __to_end,
312 extern_type*& __to_next)
const 314 result __ret = codecvt_base::error;
317 const descriptor_type& __desc = __state.out_descriptor();
318 const size_t __fmultiple =
sizeof(intern_type);
319 size_t __fbytes = __fmultiple * (__from_end - __from);
320 const size_t __tmultiple =
sizeof(extern_type);
321 size_t __tbytes = __tmultiple * (__to_end - __to);
325 char* __cto = reinterpret_cast<char*>(__to);
334 int __int_bom = __state.internal_bom();
337 size_t __size = __from_end - __from;
338 intern_type* __cfixed = static_cast<intern_type*>
339 (__builtin_alloca(
sizeof(intern_type) * (__size + 1)));
340 __cfixed[0] = static_cast<intern_type>(__int_bom);
342 __cfrom = reinterpret_cast<char*>(__cfixed);
343 __conv = __iconv_adaptor(iconv, __desc, &__cfrom,
344 &__fbytes, &__cto, &__tbytes);
348 intern_type* __cfixed = const_cast<intern_type*>(__from);
349 __cfrom = reinterpret_cast<char*>(__cfixed);
350 __conv = __iconv_adaptor(iconv, __desc, &__cfrom, &__fbytes,
354 if (__conv !=
size_t(-1))
356 __from_next = reinterpret_cast<const intern_type*>(__cfrom);
357 __to_next = reinterpret_cast<extern_type*>(__cto);
358 __ret = codecvt_base::ok;
362 if (__fbytes < __fmultiple * (__from_end - __from))
364 __from_next = reinterpret_cast<const intern_type*>(__cfrom);
365 __to_next = reinterpret_cast<extern_type*>(__cto);
366 __ret = codecvt_base::partial;
369 __ret = codecvt_base::error;
375 template<
typename _InternT,
typename _ExternT>
378 do_unshift(state_type& __state, extern_type* __to,
379 extern_type* __to_end, extern_type*& __to_next)
const 381 result __ret = codecvt_base::error;
384 const descriptor_type& __desc = __state.in_descriptor();
385 const size_t __tmultiple =
sizeof(intern_type);
386 size_t __tlen = __tmultiple * (__to_end - __to);
390 char* __cto = reinterpret_cast<char*>(__to);
391 size_t __conv = __iconv_adaptor(iconv,__desc, 0, 0,
394 if (__conv !=
size_t(-1))
396 __to_next = reinterpret_cast<extern_type*>(__cto);
397 if (__tlen == __tmultiple * (__to_end - __to))
398 __ret = codecvt_base::noconv;
399 else if (__tlen == 0)
400 __ret = codecvt_base::ok;
402 __ret = codecvt_base::partial;
405 __ret = codecvt_base::error;
410 template<
typename _InternT,
typename _ExternT>
412 codecvt<_InternT, _ExternT, encoding_state>::
413 do_in(state_type& __state,
const extern_type* __from,
414 const extern_type* __from_end,
const extern_type*& __from_next,
415 intern_type* __to, intern_type* __to_end,
416 intern_type*& __to_next)
const 418 result __ret = codecvt_base::error;
421 const descriptor_type& __desc = __state.in_descriptor();
422 const size_t __fmultiple =
sizeof(extern_type);
423 size_t __flen = __fmultiple * (__from_end - __from);
424 const size_t __tmultiple =
sizeof(intern_type);
425 size_t __tlen = __tmultiple * (__to_end - __to);
429 char* __cto = reinterpret_cast<char*>(__to);
438 int __ext_bom = __state.external_bom();
441 size_t __size = __from_end - __from;
442 extern_type* __cfixed = static_cast<extern_type*>
443 (__builtin_alloca(
sizeof(extern_type) * (__size + 1)));
444 __cfixed[0] = static_cast<extern_type>(__ext_bom);
445 char_traits<extern_type>::copy(__cfixed + 1, __from, __size);
446 __cfrom = reinterpret_cast<char*>(__cfixed);
447 __conv = __iconv_adaptor(iconv, __desc, &__cfrom,
448 &__flen, &__cto, &__tlen);
452 extern_type* __cfixed = const_cast<extern_type*>(__from);
453 __cfrom = reinterpret_cast<char*>(__cfixed);
454 __conv = __iconv_adaptor(iconv, __desc, &__cfrom,
455 &__flen, &__cto, &__tlen);
459 if (__conv !=
size_t(-1))
461 __from_next = reinterpret_cast<const extern_type*>(__cfrom);
462 __to_next = reinterpret_cast<intern_type*>(__cto);
463 __ret = codecvt_base::ok;
467 if (__flen < static_cast<size_t>(__from_end - __from))
469 __from_next = reinterpret_cast<const extern_type*>(__cfrom);
470 __to_next = reinterpret_cast<intern_type*>(__cto);
471 __ret = codecvt_base::partial;
474 __ret = codecvt_base::error;
480 template<
typename _InternT,
typename _ExternT>
482 codecvt<_InternT, _ExternT, encoding_state>::
483 do_encoding()
const throw()
486 if (
sizeof(_ExternT) <=
sizeof(_InternT))
487 __ret =
sizeof(_InternT) /
sizeof(_ExternT);
491 template<
typename _InternT,
typename _ExternT>
493 codecvt<_InternT, _ExternT, encoding_state>::
494 do_always_noconv()
const throw()
497 template<
typename _InternT,
typename _ExternT>
499 codecvt<_InternT, _ExternT, encoding_state>::
500 do_length(state_type&,
const extern_type* __from,
501 const extern_type* __end,
size_t __max)
const 502 {
return std::min(__max, static_cast<size_t>(__end - __from)); }
506 template<
typename _InternT,
typename _ExternT>
508 codecvt<_InternT, _ExternT, encoding_state>::
509 do_max_length()
const throw()
512 _GLIBCXX_END_NAMESPACE_VERSION
Common base for codecvt functions.
Class representing stream positions.
GNU extensions for public use.
ISO C++ entities toplevel namespace is std.
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
Basis for explicit traits specializations.
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.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
Extension to use iconv for dealing with character encodings.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
Primary class template codecvt.NB: Generic, mostly useless implementation.
Facet ID class.The ID class provides facets with an index used to identify them. Every facet class mu...