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
stdext::cvt::codecvt_utf16< _Elem, _Maxcode, _Mode > Class Template Reference
Inheritance diagram for stdext::cvt::codecvt_utf16< _Elem, _Maxcode, _Mode >:

Public Types

typedef _STD 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 Member Functions

 codecvt_utf16 (size_t _Refs=0)
 
virtual ~codecvt_utf16 () _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()
 

Private Types

enum  { _Bytes_per_word = 2 }
 

Member Typedef Documentation

template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0>
typedef char stdext::cvt::codecvt_utf16< _Elem, _Maxcode, _Mode >::_Byte
template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0>
typedef _STD codecvt<_Elem, char, _Statype> stdext::cvt::codecvt_utf16< _Elem, _Maxcode, _Mode >::_Mybase
template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0>
typedef _Byte stdext::cvt::codecvt_utf16< _Elem, _Maxcode, _Mode >::extern_type
template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0>
typedef _Elem stdext::cvt::codecvt_utf16< _Elem, _Maxcode, _Mode >::intern_type
template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0>
typedef _Mybase::result stdext::cvt::codecvt_utf16< _Elem, _Maxcode, _Mode >::result
template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0>
typedef _Statype stdext::cvt::codecvt_utf16< _Elem, _Maxcode, _Mode >::state_type

Member Enumeration Documentation

template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0>
anonymous enum
private
Enumerator
_Bytes_per_word 

Constructor & Destructor Documentation

template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0>
stdext::cvt::codecvt_utf16< _Elem, _Maxcode, _Mode >::codecvt_utf16 ( size_t  _Refs = 0)
inlineexplicit
43  : _Mybase(_Refs)
44  { // construct with ref count
45  }
_STD codecvt< _Elem, char, _Statype > _Mybase
Definition: utf16:35
template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0>
virtual stdext::cvt::codecvt_utf16< _Elem, _Maxcode, _Mode >::~codecvt_utf16 ( )
inlinevirtual
48  { // destroy the object
49  }

Member Function Documentation

template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0>
virtual bool stdext::cvt::codecvt_utf16< _Elem, _Maxcode, _Mode >::do_always_noconv ( ) const
inlineprotectedvirtual
260  { // return true if conversions never change input
261  return (false);
262  }
template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0>
virtual int stdext::cvt::codecvt_utf16< _Elem, _Maxcode, _Mode >::do_encoding ( ) const
inlineprotectedvirtual
271  { // return length of code sequence (from codecvt)
272  return ((_Mode & (_STD consume_header | _STD generate_header)) != 0
273  ? -1 : 0); // -1 => state dependent, 0 => varying length
274  }
Definition: codecvt:25
Definition: codecvt:24
_Check_return_ _In_z_ wchar_t const * _Mode
Definition: corecrt_wstdio.h:133
template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0>
virtual result stdext::cvt::codecvt_utf16< _Elem, _Maxcode, _Mode >::do_in ( _Statype _State,
const _Byte _First1,
const _Byte _Last1,
const _Byte *&  _Mid1,
_Elem *  _First2,
_Elem *  _Last2,
_Elem *&  _Mid2 
) const
inlineprotectedvirtual
55  { // convert bytes [_First1, _Last1) to [_First2, _Last)
56  char *_Pstate = (char *)&_State;
57  _Mid1 = _First1;
58  _Mid2 = _First2;
59 
60  for (; _Bytes_per_word <= _Last1 - _Mid1 && _Mid2 != _Last2; )
61  { // convert a multibyte sequence
62  unsigned char *_Ptr = (unsigned char *)_Mid1;
63  unsigned long _Ch;
64  unsigned short _Ch0, _Ch1;
65 
66  if (*_Pstate == _LITTLE_FIRST)
67  _Ch0 = (unsigned short)(_Ptr[1] << 8 | _Ptr[0]);
68  else if (*_Pstate == _BIG_FIRST)
69  _Ch0 = (unsigned short)(_Ptr[0] << 8 | _Ptr[1]);
70  else
71  { // no header seen yet, try preferred mode
72  unsigned char _Default_endian =
73  (_Mode & _STD little_endian) != 0
75 
76  if ((_Mode & _STD little_endian) != 0)
77  _Ch0 = (unsigned short)(_Ptr[1] << 8 | _Ptr[0]);
78  else
79  _Ch0 = (unsigned short)(_Ptr[0] << 8 | _Ptr[1]);
80  if ((_Mode & _STD consume_header) == 0
81  || (_Ch0 != 0xfeff && _Ch0 != 0xfffe))
82  *_Pstate = _Default_endian;
83  else
84  { // consume header, fixate on endianness, and retry
85  _Mid1 += _Bytes_per_word;
86  *_Pstate = (char)(_Ch0 == 0xfeff
87  ? _Default_endian
88  : (unsigned char)(3 - _Default_endian));
89  result _Ans = do_in(_State, _Mid1, _Last1, _Mid1,
90  _First2, _Last2, _Mid2);
91 
92  if (_Ans == _Mybase::partial)
93  { // not enough bytes, roll back header
94  *_Pstate = 0;
95  _Mid1 = _First1;
96  }
97  return (_Ans);
98  }
99  }
100 
101  if (_Ch0 < 0xd800 || 0xdc00 <= _Ch0)
102  { // one word, consume bytes
103  _Mid1 += _Bytes_per_word;
104  _Ch = _Ch0;
105  }
106  else if (_Last1 - _Mid1 < 2 * _Bytes_per_word)
107  break;
108  else
109  { // get second word
110  if (*_Pstate == _LITTLE_FIRST)
111  _Ch1 = (unsigned short)(_Ptr[3] << 8 | _Ptr[2]);
112  else
113  _Ch1 = (unsigned short)(_Ptr[2] << 8 | _Ptr[3]);
114 
115  if (_Ch1 < 0xdc00 || 0xe000 <= _Ch1)
116  return (_Mybase::error);
117 
118  _Mid1 += 2 * _Bytes_per_word;
119  _Ch = (unsigned long)(_Ch0 - 0xd800 + 0x0040) << 10
120  | (_Ch1 - 0xdc00);
121  }
122 
123  if (_Maxcode < _Ch)
124  return (_Mybase::error); // code too large
125  *_Mid2++ = (_Elem)_Ch;
126  }
127 
128  return (_First1 == _Mid1 ? _Mybase::partial : _Mybase::ok);
129  }
_In_ long
Definition: corecrt_wstdlib.h:88
virtual result do_in(_Statype &_State, const _Byte *_First1, const _Byte *_Last1, const _Byte *&_Mid1, _Elem *_First2, _Elem *_Last2, _Elem *&_Mid2) const
Definition: utf16:52
Definition: codecvt:26
Definition: codecvt:24
#define _BIG_FIRST
Definition: codecvt:20
_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
_Check_return_ _In_z_ wchar_t const * _Mode
Definition: corecrt_wstdio.h:133
unsigned char
Definition: mbstring.h:107
_Mybase::result result
Definition: utf16:36
#define _LITTLE_FIRST
Definition: codecvt:19
template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0>
virtual int stdext::cvt::codecvt_utf16< _Elem, _Maxcode, _Mode >::do_length ( _Statype _State,
const _Byte _First1,
const _Byte _Last1,
size_t  _Count 
) const
inlineprotectedvirtual
229  { // return min(_Count, converted length of bytes [_First1, _Last1))
230  size_t _Wchars = 0;
231  _Statype _Mystate = _State;
232 
233  for (; _Wchars < _Count && _First1 != _Last1; )
234  { // convert another wide char
235  const _Byte *_Mid1;
236  _Elem *_Mid2;
237  _Elem _Ch;
238 
239  switch (do_in(_Mystate, _First1, _Last1, _Mid1,
240  &_Ch, &_Ch + 1, _Mid2))
241  { // test result of single wide-char conversion
242  case _Mybase::noconv:
243  return ((int)(_Wchars + (_Last1 - _First1)));
244 
245  case _Mybase::ok:
246  if (_Mid2 == &_Ch + 1)
247  ++_Wchars; // replacement do_in might not convert one
248  _First1 = _Mid1;
249  break;
250 
251  default:
252  return ((int)_Wchars); // error or partial
253  }
254  }
255 
256  return ((int)_Wchars);
257  }
virtual result do_in(_Statype &_State, const _Byte *_First1, const _Byte *_Last1, const _Byte *&_Mid1, _Elem *_First2, _Elem *_Last2, _Elem *&_Mid2) const
Definition: utf16:52
_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
char _Byte
Definition: utf16:37
_Diff _Count
Definition: algorithm:1941
_CSTD mbstate_t _Statype
Definition: codecvt:28
template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0>
virtual int stdext::cvt::codecvt_utf16< _Elem, _Maxcode, _Mode >::do_max_length ( ) const
inlineprotectedvirtual
265  { // return maximum length required for a conversion
266  return ((_Mode & (_STD consume_header | _STD generate_header)) != 0
267  ? 3 * _Bytes_per_word : 6 * _Bytes_per_word);
268  }
Definition: codecvt:25
Definition: codecvt:24
_Check_return_ _In_z_ wchar_t const * _Mode
Definition: corecrt_wstdio.h:133
template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0>
virtual result stdext::cvt::codecvt_utf16< _Elem, _Maxcode, _Mode >::do_out ( _Statype _State,
const _Elem *  _First1,
const _Elem *  _Last1,
const _Elem *&  _Mid1,
_Byte _First2,
_Byte _Last2,
_Byte *&  _Mid2 
) const
inlineprotectedvirtual
134  { // convert [_First1, _Last1) to bytes [_First2, _Last)
135  char *_Pstate = (char *)&_State;
136  _Mid1 = _First1;
137  _Mid2 = _First2;
138 
139  if (*_Pstate == 0)
140  { // determine endianness once, maybe generate header
141  *_Pstate = (_Mode & _STD little_endian) != 0
143  if ((_Mode & _STD generate_header) == 0)
144  ;
145  else if (_Last2 - _Mid2 < 3 * _Bytes_per_word)
146  return (_Mybase::partial); // not enough room for both
147  else if (*_Pstate == _LITTLE_FIRST)
148  { // put header LS byte first
149  *_Mid2++ = (_Byte)(unsigned char)0xff;
150  *_Mid2++ = (_Byte)(unsigned char)0xfe;
151  }
152  else
153  { // put header MS byte first
154  *_Mid2++ = (_Byte)(unsigned char)0xfe;
155  *_Mid2++ = (_Byte)(unsigned char)0xff;
156  }
157  }
158 
159  for (; _Mid1 != _Last1 && _Bytes_per_word <= _Last2 - _Mid2; )
160  { // convert and put a wide char
161  bool _Extra = false;
162  unsigned long _Ch = (unsigned long)*_Mid1++;
163 
164  if ((_Maxcode < 0x10ffff ? _Maxcode : 0x10ffff) < _Ch)
165  return (_Mybase::error); // value too large
166  else if (_Ch <= 0xffff)
167  { // one word, can't be code for first of two
168  if (0xd800 <= _Ch && _Ch < 0xdc00)
169  return (_Mybase::error);
170  }
171  else if (_Last2 - _Mid2 < 2 * _Bytes_per_word)
172  { // not enough room for two-word output, back up
173  --_Mid1;
174  return (_Mybase::partial);
175  }
176  else
177  _Extra = true;
178 
179  if (*_Pstate == _LITTLE_FIRST)
180  if (!_Extra)
181  { // put a single word LS byte first
182  *_Mid2++ = (_Byte)_Ch;
183  *_Mid2++ = (_Byte)(_Ch >> 8);
184  }
185  else
186  { // put a pair of words LS byte first
187  unsigned short _Ch0 = (unsigned short)(0xd800
188  | (unsigned short)(_Ch >> 10) - 0x0040);
189  *_Mid2++ = (_Byte)_Ch0;
190  *_Mid2++ = (_Byte)(_Ch0 >> 8);
191 
192  _Ch0 = (unsigned short)(0xdc00
193  | ((unsigned short)_Ch & 0x03ff));
194  *_Mid2++ = (_Byte)_Ch0;
195  *_Mid2++ = (_Byte)(_Ch0 >> 8);
196  }
197  else
198  if (!_Extra)
199  { // put a single word MS byte first
200  *_Mid2++ = (_Byte)(_Ch >> 8);
201  *_Mid2++ = (_Byte)_Ch;
202  }
203  else
204  { // put a pair of words MS byte first
205  unsigned short _Ch0 = (unsigned short)(0xd800
206  | (unsigned short)(_Ch >> 10) - 0x0040);
207  *_Mid2++ = (_Byte)(_Ch0 >> 8);
208  *_Mid2++ = (_Byte)_Ch0;
209 
210  _Ch0 = (unsigned short)(0xdc00
211  | ((unsigned short)_Ch & 0x03ff));
212  *_Mid2++ = (_Byte)(_Ch0 >> 8);
213  *_Mid2++ = (_Byte)_Ch0;
214  }
215  }
216 
217  return (_First1 == _Mid1 ? _Mybase::partial : _Mybase::ok);
218  }
Definition: codecvt:25
_In_ long
Definition: corecrt_wstdlib.h:88
Definition: codecvt:26
#define _BIG_FIRST
Definition: codecvt:20
_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
_Check_return_ _In_z_ wchar_t const * _Mode
Definition: corecrt_wstdio.h:133
char _Byte
Definition: utf16:37
#define _LITTLE_FIRST
Definition: codecvt:19
template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0>
virtual result stdext::cvt::codecvt_utf16< _Elem, _Maxcode, _Mode >::do_unshift ( _Statype ,
_Byte _First2,
_Byte ,
_Byte *&  _Mid2 
) const
inlineprotectedvirtual
222  { // generate bytes to return to default shift state
223  _Mid2 = _First2;
224  return (_Mybase::ok);
225  }

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