STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Types | Public Member Functions | Protected Member Functions | List of all members
codecvt_utf8_utf16< _Elem, _Mymax, _Mymode > Class Template Reference
Inheritance diagram for codecvt_utf8_utf16< _Elem, _Mymax, _Mymode >:
codecvt< _Elem, char, _Statype > codecvt_base locale::facet _Facet_base

Public Types

typedef codecvt< _Elem, char, _Statype_Mybase
 
typedef _Mybase::result result
 
typedef char _Byte
 
typedef _Elem intern_type
 
typedef _Byte extern_type
 
typedef _Statype state_type
 
- Public Types inherited from codecvt< _Elem, char, _Statype >
typedef _Elem intern_type
 
typedef char extern_type
 
typedef _Statype state_type
 
- Public Types inherited from codecvt_base
enum  { ok, partial, error, noconv }
 
typedef int result
 

Public Member Functions

 codecvt_utf8_utf16 (size_t _Refs=0)
 
virtual ~codecvt_utf8_utf16 () _NOEXCEPT
 
- Public Member Functions inherited from codecvt< _Elem, char, _Statype >
result __CLR_OR_THIS_CALL in (_Statype &_State, const char *_First1, const char *_Last1, const char *&_Mid1, _Elem *_First2, _Elem *_Last2, _Elem *&_Mid2) const
 
result __CLR_OR_THIS_CALL out (_Statype &_State, const _Elem *_First1, const _Elem *_Last1, const _Elem *&_Mid1, char *_First2, char *_Last2, char *&_Mid2) const
 
result __CLR_OR_THIS_CALL unshift (_Statype &_State, char *_First2, char *_Last2, char *&_Mid2) const
 
int __CLR_OR_THIS_CALL length (_Statype &_State, const char *_First1, const char *_Last1, size_t _Count) const
 
__CLR_OR_THIS_CALL codecvt (size_t _Refs=0)
 
__CLR_OR_THIS_CALL codecvt (const _Locinfo &_Lobj, size_t _Refs=0)
 
- Public Member Functions inherited from codecvt_base
__CLR_OR_THIS_CALL codecvt_base (size_t _Refs=0)
 
bool __CLR_OR_THIS_CALL always_noconv () const _THROW0()
 
int __CLR_OR_THIS_CALL max_length () const _THROW0()
 
int __CLR_OR_THIS_CALL encoding () const _THROW0()
 
__CLR_OR_THIS_CALL ~codecvt_base () _NOEXCEPT
 
- Public Member Functions inherited from locale::facet
virtual void __CLR_OR_THIS_CALL _Incref ()
 
virtual _Facet_base *__CLR_OR_THIS_CALL _Decref ()
 
__CLR_OR_THIS_CALL facet (const facet &)=delete
 
facet &__CLR_OR_THIS_CALL operator= (const facet &)=delete
 
- Public Member Functions inherited from _Facet_base
virtual __CLR_OR_THIS_CALL ~_Facet_base () _NOEXCEPT
 

Protected Member Functions

virtual result do_in (_Statype &_State, const _Byte *_First1, const _Byte *_Last1, const _Byte *&_Mid1, _Elem *_First2, _Elem *_Last2, _Elem *&_Mid2) const
 
virtual result do_out (_Statype &_State, const _Elem *_First1, const _Elem *_Last1, const _Elem *&_Mid1, _Byte *_First2, _Byte *_Last2, _Byte *&_Mid2) const
 
virtual result do_unshift (_Statype &_State, _Byte *_First2, _Byte *, _Byte *&_Mid2) const
 
virtual int do_length (_Statype &_State, const _Byte *_First1, const _Byte *_Last1, size_t _Count) const _THROW0()
 
virtual bool do_always_noconv () const _THROW0()
 
virtual int do_max_length () const _THROW0()
 
virtual int do_encoding () const _THROW0()
 
- Protected Member Functions inherited from codecvt< _Elem, char, _Statype >
virtual __CLR_OR_THIS_CALL ~codecvt () _NOEXCEPT
 
void __CLR_OR_THIS_CALL _Init (const _Locinfo &)
 
- Protected Member Functions inherited from locale::facet
__CLR_OR_THIS_CALL facet (size_t _Initrefs=0)
 
virtual __CLR_OR_THIS_CALL ~facet () _NOEXCEPT
 

Additional Inherited Members

- Static Public Member Functions inherited from codecvt< _Elem, char, _Statype >
static size_t __CLRCALL_OR_CDECL _Getcat (const locale::facet **_Ppf=0, const locale *_Ploc=0)
 
- Static Public Member Functions inherited from locale::facet
static size_t __CLRCALL_OR_CDECL _Getcat (const facet **=0, const locale *=0)
 
- Static Public Attributes inherited from codecvt< _Elem, char, _Statype >
static __PURE_APPDOMAIN_GLOBAL locale::id id
 

Member Typedef Documentation

template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
typedef char codecvt_utf8_utf16< _Elem, _Mymax, _Mymode >::_Byte
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
typedef codecvt<_Elem, char, _Statype> codecvt_utf8_utf16< _Elem, _Mymax, _Mymode >::_Mybase
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
typedef _Byte codecvt_utf8_utf16< _Elem, _Mymax, _Mymode >::extern_type
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
typedef _Elem codecvt_utf8_utf16< _Elem, _Mymax, _Mymode >::intern_type
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
typedef _Mybase::result codecvt_utf8_utf16< _Elem, _Mymax, _Mymode >::result
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
typedef _Statype codecvt_utf8_utf16< _Elem, _Mymax, _Mymode >::state_type

Constructor & Destructor Documentation

template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
codecvt_utf8_utf16< _Elem, _Mymax, _Mymode >::codecvt_utf8_utf16 ( size_t  _Refs = 0)
inlineexplicit
501  : _Mybase(_Refs)
502  { // construct with ref count
503  }
codecvt< _Elem, char, _Statype > _Mybase
Definition: codecvt:490
_Atomic_counter_t _Refs
Definition: xlocale:157
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
virtual codecvt_utf8_utf16< _Elem, _Mymax, _Mymode >::~codecvt_utf8_utf16 ( )
inlinevirtual
506  { // destroy the object
507  }

Member Function Documentation

template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
virtual bool codecvt_utf8_utf16< _Elem, _Mymax, _Mymode >::do_always_noconv ( ) const
inlineprotectedvirtual

Reimplemented from codecvt< _Elem, char, _Statype >.

729  { // return true if conversions never change input
730  return (false);
731  }
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
virtual int codecvt_utf8_utf16< _Elem, _Mymax, _Mymode >::do_encoding ( ) const
inlineprotectedvirtual

Reimplemented from codecvt_base.

741  { // return length of code sequence (from codecvt)
742  return (0); // 0 => varying length
743  }
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
virtual result codecvt_utf8_utf16< _Elem, _Mymax, _Mymode >::do_in ( _Statype _State,
const _Byte _First1,
const _Byte _Last1,
const _Byte *&  _Mid1,
_Elem *  _First2,
_Elem *  _Last2,
_Elem *&  _Mid2 
) const
inlineprotectedvirtual

Reimplemented from codecvt< _Elem, char, _Statype >.

513  { // convert bytes [_First1, _Last1) to [_First2, _Last2)
514  unsigned short *_Pstate = (unsigned short *)&_State;
515  _Mid1 = _First1;
516  _Mid2 = _First2;
517 
518  for (; _Mid1 != _Last1 && _Mid2 != _Last2; )
519  { // convert a multibyte sequence
520  unsigned char _By = (unsigned char)*_Mid1;
521  unsigned long _Ch;
522  int _Nextra, _Nskip;
523 
524  if (*_Pstate <= 1)
525  ; // no leftover word
526  else if (_By < 0x80 || 0xc0 <= _By)
527  return (_Mybase::error); // not continuation byte
528  else
529  { // deliver second half of two-word value
530  ++_Mid1;
531  *_Mid2++ = (_Elem)(*_Pstate | (_By & 0x3f));
532  *_Pstate = 1;
533  continue;
534  }
535 
536  if (_By < 0x80)
537  _Ch = _By, _Nextra = 0;
538  else if (_By < 0xc0)
539  { // 0x80-0xdf not first byte
540  ++_Mid1;
541  return (_Mybase::error);
542  }
543  else if (_By < 0xe0)
544  _Ch = _By & 0x1f, _Nextra = 1;
545  else if (_By < 0xf0)
546  _Ch = _By & 0x0f, _Nextra = 2;
547  else if (_By < 0xf8)
548  _Ch = _By & 0x07, _Nextra = 3;
549  else
550  _Ch = _By & 0x03, _Nextra = _By < 0xfc ? 4 : 5;
551 
552  _Nskip = _Nextra < 3 ? 0 : 1; // leave a byte for 2nd word
553  _First1 = _Mid1; // roll back point
554 
555  if (_Nextra == 0)
556  ++_Mid1;
557  else if (_Last1 - _Mid1 < _Nextra + 1 - _Nskip)
558  break; // not enough input
559  else
560  for (++_Mid1; _Nskip < _Nextra; --_Nextra, ++_Mid1)
561  if ((_By = (unsigned char)*_Mid1) < 0x80 || 0xc0 <= _By)
562  return (_Mybase::error); // not continuation byte
563  else
564  _Ch = _Ch << 6 | (_By & 0x3f);
565  if (0 < _Nskip)
566  _Ch <<= 6; // get last byte on next call
567 
568  if ((_Mymax < 0x10ffff ? _Mymax : 0x10ffff) < _Ch)
569  return (_Mybase::error); // value too large
570  else if (0xffff < _Ch)
571  { // deliver first half of two-word value, save second word
572  unsigned short _Ch0 =
573  (unsigned short)(0xd800 | (_Ch >> 10) - 0x0040);
574 
575  *_Mid2++ = (_Elem)_Ch0;
576  *_Pstate = (unsigned short)(0xdc00 | (_Ch & 0x03ff));
577  continue;
578  }
579 
580  if (_Nskip == 0)
581  ;
582  else if (_Mid1 == _Last1)
583  { // not enough bytes, noncanonical value
584  _Mid1 = _First1;
585  break;
586  }
587  else if ((_By = (unsigned char)*_Mid1++) < 0x80 || 0xc0 <= _By)
588  return (_Mybase::error); // not continuation byte
589  else
590  _Ch |= _By & 0x3f; // complete noncanonical value
591 
592  if (*_Pstate == 0)
593  { // first time, maybe look for and consume header
594  *_Pstate = 1;
595 
596  if ((_Mymode & consume_header) != 0 && _Ch == 0xfeff)
597  { // drop header and retry
598  result _Ans = do_in(_State, _Mid1, _Last1, _Mid1,
599  _First2, _Last2, _Mid2);
600 
601  if (_Ans == _Mybase::partial)
602  { // roll back header determination
603  *_Pstate = 0;
604  _Mid1 = _First1;
605  }
606  return (_Ans);
607  }
608  }
609 
610  *_Mid2++ = (_Elem)_Ch;
611  }
612 
613  return (_First1 == _Mid1 ? _Mybase::partial : _Mybase::ok);
614  }
Definition: xlocale:816
Definition: xlocale:816
Definition: codecvt:22
virtual result do_in(_Statype &_State, const _Byte *_First1, const _Byte *_Last1, const _Byte *&_Mid1, _Elem *_First2, _Elem *_Last2, _Elem *&_Mid2) const
Definition: codecvt:510
Definition: xlocale:816
_In_ size_t _In_ unsigned int _Ch
Definition: mbstring.h:161
_Mybase::result result
Definition: codecvt:491
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
virtual int codecvt_utf8_utf16< _Elem, _Mymax, _Mymode >::do_length ( _Statype _State,
const _Byte _First1,
const _Byte _Last1,
size_t  _Count 
) const
inlineprotectedvirtual

Reimplemented from codecvt< _Elem, char, _Statype >.

698  { // return min(_Count, converted length of bytes [_First1, _Last1))
699  size_t _Wchars = 0;
700  _Statype _Mystate = _State;
701 
702  for (; _Wchars < _Count && _First1 != _Last1; )
703  { // convert another wide character
704  const _Byte *_Mid1;
705  _Elem *_Mid2;
706  _Elem _Ch;
707 
708  switch (do_in(_Mystate, _First1, _Last1, _Mid1,
709  &_Ch, &_Ch + 1, _Mid2))
710  { // test result of single wide-char conversion
711  case _Mybase::noconv:
712  return ((int)(_Wchars + (_Last1 - _First1)));
713 
714  case _Mybase::ok:
715  if (_Mid2 == &_Ch + 1)
716  ++_Wchars; // replacement do_in might not convert one
717  _First1 = _Mid1;
718  break;
719 
720  default:
721  return ((int)_Wchars); // error or partial
722  }
723  }
724 
725  return ((int)_Wchars);
726  }
Definition: xlocale:816
Definition: xlocale:816
virtual result do_in(_Statype &_State, const _Byte *_First1, const _Byte *_Last1, const _Byte *&_Mid1, _Elem *_First2, _Elem *_Last2, _Elem *&_Mid2) const
Definition: codecvt:510
char _Byte
Definition: codecvt:492
_In_ size_t _In_ unsigned int _Ch
Definition: mbstring.h:161
_Diff _Count
Definition: algorithm:1941
_CSTD mbstate_t _Statype
Definition: codecvt:26
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
virtual int codecvt_utf8_utf16< _Elem, _Mymax, _Mymode >::do_max_length ( ) const
inlineprotectedvirtual

Reimplemented from codecvt_base.

734  { // return maximum length required for a conversion
735  return ((_Mymode & consume_header) != 0 ? 9 // header + max input
736  : (_Mymode & generate_header) != 0 ? 7 // header + max output
737  : 6); // 6-byte max input sequence, no 3-byte header
738  }
Definition: codecvt:23
Definition: codecvt:22
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
virtual result codecvt_utf8_utf16< _Elem, _Mymax, _Mymode >::do_out ( _Statype _State,
const _Elem *  _First1,
const _Elem *  _Last1,
const _Elem *&  _Mid1,
_Byte _First2,
_Byte _Last2,
_Byte *&  _Mid2 
) const
inlineprotectedvirtual

Reimplemented from codecvt< _Elem, char, _Statype >.

619  { // convert [_First1, _Last1) to bytes [_First2, _Last)
620  unsigned short *_Pstate = (unsigned short *)&_State;
621  _Mid1 = _First1;
622  _Mid2 = _First2;
623 
624  for (; _Mid1 != _Last1 && _Mid2 != _Last2; )
625  { // convert and put a wide char
626  unsigned long _Ch;
627  unsigned short _Ch1 = (unsigned short)*_Mid1;
628  bool _Save = false;
629 
630  if (1 < *_Pstate)
631  { // get saved MS 11 bits from *_Pstate
632  if (_Ch1 < 0xdc00 || 0xe000 <= _Ch1)
633  return (_Mybase::error); // bad second word
634  _Ch = (*_Pstate << 10) | (_Ch1 - 0xdc00);
635  }
636  else if (0xd800 <= _Ch1 && _Ch1 < 0xdc00)
637  { // get new first word
638  _Ch = (_Ch1 - 0xd800 + 0x0040) << 10;
639  _Save = true; // put only first byte, rest with second word
640  }
641  else
642  _Ch = _Ch1; // not first word, just put it
643 
644  _Byte _By;
645  int _Nextra;
646 
647  if (_Ch < 0x0080)
648  _By = (_Byte)_Ch, _Nextra = 0;
649  else if (_Ch < 0x0800)
650  _By = (_Byte)(0xc0 | _Ch >> 6), _Nextra = 1;
651  else if (_Ch < 0x10000)
652  _By = (_Byte)(0xe0 | _Ch >> 12), _Nextra = 2;
653  else
654  _By = (_Byte)(0xf0 | _Ch >> 18), _Nextra = 3;
655 
656  int _Nput = _Nextra < 3 ? _Nextra + 1 : _Save ? 1 : 3;
657 
658  if (_Last2 - _Mid2 < _Nput)
659  break; // not enough room, even without header
660  else if (*_Pstate != 0 || (_Mymode & generate_header) == 0)
661  ; // no header to put
662  else if (_Last2 - _Mid2 < 3 + _Nput)
663  break; // not enough room for header + output
664  else
665  { // prepend header
666  *_Mid2++ = (_Byte)(unsigned char)0xef;
667  *_Mid2++ = (_Byte)(unsigned char)0xbb;
668  *_Mid2++ = (_Byte)(unsigned char)0xbf;
669  }
670 
671  ++_Mid1;
672  if (_Save || _Nextra < 3)
673  { // put first byte of sequence, if not already put
674  *_Mid2++ = _By;
675  --_Nput;
676  }
677  for (; 0 < _Nput; --_Nput)
678  *_Mid2++ = (_Byte)((_Ch >> 6 * --_Nextra & 0x3f) | 0x80);
679 
680  *_Pstate = (unsigned short)(_Save ? _Ch >> 10 : 1);
681  }
682 
683  return (_First1 == _Mid1 ? _Mybase::partial : _Mybase::ok);
684  }
Definition: codecvt:23
Definition: xlocale:816
Definition: xlocale:816
char _Byte
Definition: codecvt:492
Definition: xlocale:816
_In_ size_t _In_ unsigned int _Ch
Definition: mbstring.h:161
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
virtual result codecvt_utf8_utf16< _Elem, _Mymax, _Mymode >::do_unshift ( _Statype _State,
_Byte _First2,
_Byte ,
_Byte *&  _Mid2 
) const
inlineprotectedvirtual

Reimplemented from codecvt< _Elem, char, _Statype >.

688  { // generate bytes to return to default shift state
689  unsigned short *_Pstate = (unsigned short *)&_State;
690  _Mid2 = _First2;
691 
692  return (1 < *_Pstate
693  ? _Mybase::error : _Mybase::ok); // fail if trailing first word
694  }
Definition: xlocale:816
Definition: xlocale:816

The documentation for this class was generated from the following file: