STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Types | Public Member Functions | Protected Member Functions | Private Types | List of all members
codecvt_utf16< _Elem, _Mymax, _Mymode > Class Template Reference
Inheritance diagram for codecvt_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_utf16 (size_t _Refs=0)
 
virtual ~codecvt_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 &, _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
 

Private Types

enum  { _Bytes_per_word = 2 }
 

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_utf16< _Elem, _Mymax, _Mymode >::_Byte
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
typedef codecvt<_Elem, char, _Statype> codecvt_utf16< _Elem, _Mymax, _Mymode >::_Mybase
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
typedef _Byte codecvt_utf16< _Elem, _Mymax, _Mymode >::extern_type
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
typedef _Elem codecvt_utf16< _Elem, _Mymax, _Mymode >::intern_type
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
typedef _Mybase::result codecvt_utf16< _Elem, _Mymax, _Mymode >::result
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
typedef _Statype codecvt_utf16< _Elem, _Mymax, _Mymode >::state_type

Member Enumeration Documentation

template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
anonymous enum
private
Enumerator
_Bytes_per_word 
239 {_Bytes_per_word = 2};
Definition: codecvt:239

Constructor & Destructor Documentation

template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
codecvt_utf16< _Elem, _Mymax, _Mymode >::codecvt_utf16 ( size_t  _Refs = 0)
inlineexplicit
249  : _Mybase(_Refs)
250  { // construct with ref count
251  }
codecvt< _Elem, char, _Statype > _Mybase
Definition: codecvt:241
_Atomic_counter_t _Refs
Definition: xlocale:157
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
virtual codecvt_utf16< _Elem, _Mymax, _Mymode >::~codecvt_utf16 ( )
inlinevirtual
254  { // destroy the object
255  }

Member Function Documentation

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

Reimplemented from codecvt< _Elem, char, _Statype >.

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

Reimplemented from codecvt_base.

476  { // return length of code sequence (from codecvt)
477  return ((_Mymode & (consume_header | generate_header)) != 0
478  ? -1 : 0); // -1 => state dependent, 0 => varying length
479  }
Definition: codecvt:23
Definition: codecvt:22
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
virtual result codecvt_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 >.

261  { // convert bytes [_First1, _Last1) to [_First2, _Last)
262  char *_Pstate = (char *)&_State;
263  _Mid1 = _First1;
264  _Mid2 = _First2;
265 
266  for (; _Bytes_per_word <= _Last1 - _Mid1 && _Mid2 != _Last2; )
267  { // convert a multibyte sequence
268  unsigned char *_Ptr = (unsigned char *)_Mid1;
269  unsigned long _Ch;
270  unsigned short _Ch0, _Ch1;
271 
272  if (*_Pstate == _LITTLE_FIRST)
273  _Ch0 = (unsigned short)(_Ptr[1] << 8 | _Ptr[0]);
274  else if (*_Pstate == _BIG_FIRST)
275  _Ch0 = (unsigned short)(_Ptr[0] << 8 | _Ptr[1]);
276  else
277  { // no header seen yet, try preferred mode
278  unsigned char _Default_endian = (_Mymode & little_endian) != 0
280 
281  if ((_Mymode & little_endian) != 0)
282  _Ch0 = (unsigned short)(_Ptr[1] << 8 | _Ptr[0]);
283  else
284  _Ch0 = (unsigned short)(_Ptr[0] << 8 | _Ptr[1]);
285  if ((_Mymode & consume_header) == 0
286  || (_Ch0 != 0xfeff && _Ch0 != 0xfffe))
287  *_Pstate = _Default_endian;
288  else
289  { // consume header, fixate on endianness, and retry
290  _Mid1 += _Bytes_per_word;
291  *_Pstate = (char)(_Ch0 == 0xfeff
292  ? _Default_endian
293  : (unsigned char)(3 - _Default_endian));
294  result _Ans = do_in(_State, _Mid1, _Last1, _Mid1,
295  _First2, _Last2, _Mid2);
296 
297  if (_Ans == _Mybase::partial)
298  { // not enough bytes, roll back header
299  *_Pstate = 0;
300  _Mid1 = _First1;
301  }
302  return (_Ans);
303  }
304  }
305 
306  if (_Ch0 < 0xd800 || 0xdc00 <= _Ch0)
307  { // one word, consume bytes
308  _Mid1 += _Bytes_per_word;
309  _Ch = _Ch0;
310  }
311  else if (_Last1 - _Mid1 < 2 * _Bytes_per_word)
312  break;
313  else
314  { // get second word
315  if (*_Pstate == _LITTLE_FIRST)
316  _Ch1 = (unsigned short)(_Ptr[3] << 8 | _Ptr[2]);
317  else
318  _Ch1 = (unsigned short)(_Ptr[2] << 8 | _Ptr[3]);
319 
320  if (_Ch1 < 0xdc00 || 0xe000 <= _Ch1)
321  return (_Mybase::error);
322 
323  _Mid1 += 2 * _Bytes_per_word;
324  _Ch = (unsigned long)(_Ch0 - 0xd800 + 0x0040) << 10
325  | (_Ch1 - 0xdc00);
326  }
327 
328  if (_Mymax < _Ch)
329  return (_Mybase::error); // code too large
330  *_Mid2++ = (_Elem)_Ch;
331  }
332 
333  return (_First1 == _Mid1 ? _Mybase::partial : _Mybase::ok);
334  }
Definition: codecvt:239
Definition: codecvt:24
Definition: xlocale:816
Definition: xlocale:816
Definition: codecvt:22
#define _BIG_FIRST
Definition: codecvt:18
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:258
_Mybase::result result
Definition: codecvt:242
_In_ size_t _In_ unsigned int _Ch
Definition: mbstring.h:161
#define _LITTLE_FIRST
Definition: codecvt:17
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
virtual int codecvt_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 >.

434  { // return min(_Count, converted length of bytes [_First1, _Last1))
435  size_t _Wchars = 0;
436  _Statype _Mystate = _State;
437 
438  for (; _Wchars < _Count && _First1 != _Last1; )
439  { // convert another wide char
440  const _Byte *_Mid1;
441  _Elem *_Mid2;
442  _Elem _Ch;
443 
444  switch (do_in(_Mystate, _First1, _Last1, _Mid1,
445  &_Ch, &_Ch + 1, _Mid2))
446  { // test result of single wide-char conversion
447  case _Mybase::noconv:
448  return ((int)(_Wchars + (_Last1 - _First1)));
449 
450  case _Mybase::ok:
451  if (_Mid2 == &_Ch + 1)
452  ++_Wchars; // replacement do_in might not convert one
453  _First1 = _Mid1;
454  break;
455 
456  default:
457  return ((int)_Wchars); // error or partial
458  }
459  }
460 
461  return ((int)_Wchars);
462  }
char _Byte
Definition: codecvt:243
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:258
_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_utf16< _Elem, _Mymax, _Mymode >::do_max_length ( ) const
inlineprotectedvirtual

Reimplemented from codecvt_base.

470  { // return maximum length required for a conversion
471  return ((_Mymode & (consume_header | generate_header)) != 0
472  ? 3 * _Bytes_per_word : 6 * _Bytes_per_word);
473  }
Definition: codecvt:23
Definition: codecvt:239
Definition: codecvt:22
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
virtual result codecvt_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 >.

339  { // convert [_First1, _Last1) to bytes [_First2, _Last)
340  char *_Pstate = (char *)&_State;
341  _Mid1 = _First1;
342  _Mid2 = _First2;
343 
344  if (*_Pstate == 0)
345  { // determine endianness once, maybe generate header
346  *_Pstate = (_Mymode & little_endian) != 0
348  if ((_Mymode & generate_header) == 0)
349  ;
350  else if (_Last2 - _Mid2 < 3 * _Bytes_per_word)
351  return (_Mybase::partial); // not enough room for all
352  else if (*_Pstate == _LITTLE_FIRST)
353  { // put header LS byte first
354  *_Mid2++ = (_Byte)(unsigned char)0xff;
355  *_Mid2++ = (_Byte)(unsigned char)0xfe;
356  }
357  else
358  { // put header MS byte first
359  *_Mid2++ = (_Byte)(unsigned char)0xfe;
360  *_Mid2++ = (_Byte)(unsigned char)0xff;
361  }
362  }
363 
364  for (; _Mid1 != _Last1 && _Bytes_per_word <= _Last2 - _Mid2; )
365  { // convert and put a wide char
366  bool _Extra = false;
367  unsigned long _Ch = (unsigned long)*_Mid1++;
368 
369  if ((_Mymax < 0x10ffff ? _Mymax : 0x10ffff) < _Ch)
370  return (_Mybase::error); // value too large
371  else if (_Ch <= 0xffff)
372  { // one word, can't be code for first of two
373  if (0xd800 <= _Ch && _Ch < 0xdc00)
374  return (_Mybase::error);
375  }
376  else if (_Last2 - _Mid2 < 2 * _Bytes_per_word)
377  { // not enough room for two-word output, back up
378  --_Mid1;
379  return (_Mybase::partial);
380  }
381  else
382  _Extra = true;
383 
384  if (*_Pstate == _LITTLE_FIRST)
385  if (!_Extra)
386  { // put a single word LS byte first
387  *_Mid2++ = (_Byte)_Ch;
388  *_Mid2++ = (_Byte)(_Ch >> 8);
389  }
390  else
391  { // put a pair of words LS byte first
392  unsigned short _Ch0 = (unsigned short)(0xd800
393  | (unsigned short)(_Ch >> 10) - 0x0040);
394  *_Mid2++ = (_Byte)_Ch0;
395  *_Mid2++ = (_Byte)(_Ch0 >> 8);
396 
397  _Ch0 = (unsigned short)(0xdc00
398  | ((unsigned short)_Ch & 0x03ff));
399  *_Mid2++ = (_Byte)_Ch0;
400  *_Mid2++ = (_Byte)(_Ch0 >> 8);
401  }
402  else
403  if (!_Extra)
404  { // put a single word MS byte first
405  *_Mid2++ = (_Byte)(_Ch >> 8);
406  *_Mid2++ = (_Byte)_Ch;
407  }
408  else
409  { // put a pair of words MS byte first
410  unsigned short _Ch0 = (unsigned short)(0xd800
411  | (unsigned short)(_Ch >> 10) - 0x0040);
412  *_Mid2++ = (_Byte)(_Ch0 >> 8);
413  *_Mid2++ = (_Byte)_Ch0;
414 
415  _Ch0 = (unsigned short)(0xdc00
416  | ((unsigned short)_Ch & 0x03ff));
417  *_Mid2++ = (_Byte)(_Ch0 >> 8);
418  *_Mid2++ = (_Byte)_Ch0;
419  }
420  }
421 
422  return (_First1 == _Mid1 ? _Mybase::partial : _Mybase::ok);
423  }
char _Byte
Definition: codecvt:243
Definition: codecvt:23
Definition: codecvt:239
Definition: codecvt:24
Definition: xlocale:816
Definition: xlocale:816
#define _BIG_FIRST
Definition: codecvt:18
Definition: xlocale:816
_In_ size_t _In_ unsigned int _Ch
Definition: mbstring.h:161
#define _LITTLE_FIRST
Definition: codecvt:17
template<class _Elem , unsigned long _Mymax = 0x10ffff, codecvt_mode _Mymode = (codecvt_mode)0>
virtual result codecvt_utf16< _Elem, _Mymax, _Mymode >::do_unshift ( _Statype ,
_Byte _First2,
_Byte ,
_Byte *&  _Mid2 
) const
inlineprotectedvirtual

Reimplemented from codecvt< _Elem, char, _Statype >.

427  { // generate bytes to return to default shift state
428  _Mid2 = _First2;
429  return (_Mybase::ok);
430  }
Definition: xlocale:816

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