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 _Crt_new_delete

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 __CLR_OR_THIS_CALL ~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 __CLR_OR_THIS_CALL do_in (_Statype &_State, const _Byte *_First1, const _Byte *_Last1, const _Byte *&_Mid1, _Elem *_First2, _Elem *_Last2, _Elem *&_Mid2) const
 
virtual result __CLR_OR_THIS_CALL do_out (_Statype &_State, const _Elem *_First1, const _Elem *_Last1, const _Elem *&_Mid1, _Byte *_First2, _Byte *_Last2, _Byte *&_Mid2) const
 
virtual result __CLR_OR_THIS_CALL do_unshift (_Statype &_State, _Byte *_First2, _Byte *, _Byte *&_Mid2) const
 
virtual int __CLR_OR_THIS_CALL do_length (_Statype &_State, const _Byte *_First1, const _Byte *_Last1, size_t _Count) const _THROW0()
 
virtual bool __CLR_OR_THIS_CALL do_always_noconv () const _THROW0()
 
virtual int __CLR_OR_THIS_CALL do_max_length () const _THROW0()
 
virtual int __CLR_OR_THIS_CALL 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
503  : _Mybase(_Refs)
504  { // construct with ref count
505  }
codecvt< _Elem, char, _Statype > _Mybase
Definition: codecvt:492
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
virtual __CLR_OR_THIS_CALL codecvt_utf8_utf16< _Elem, _Mymax, _Mymode >::~codecvt_utf8_utf16 ( )
inlinevirtual
508  { // destroy the object
509  }

Member Function Documentation

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

Reimplemented from codecvt< _Elem, char, _Statype >.

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

Reimplemented from codecvt_base.

743  { // return length of code sequence (from codecvt)
744  return (0); // 0 => varying length
745  }
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
virtual result __CLR_OR_THIS_CALL 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 >.

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

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

Reimplemented from codecvt_base.

736  { // return maximum length required for a conversion
737  return ((_Mymode & consume_header) != 0 ? 9 // header + max input
738  : (_Mymode & generate_header) != 0 ? 7 // header + max output
739  : 6); // 6-byte max input sequence, no 3-byte header
740  }
Definition: codecvt:25
Definition: codecvt:24
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
virtual result __CLR_OR_THIS_CALL 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 >.

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

Reimplemented from codecvt< _Elem, char, _Statype >.

690  { // generate bytes to return to default shift state
691  unsigned short *_Pstate = (unsigned short *)&_State;
692  _Mid2 = _First2;
693 
694  return (1 < *_Pstate
695  ? _Mybase::error : _Mybase::ok); // fail if trailing first word
696  }
Definition: xlocale:759
_In_ size_t _Deref_pre_opt_z_ char const _In_ size_t _Inout_ mbstate_t * _State
Definition: wchar.h:78
Definition: xlocale:759

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