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
42  : _Mybase(_Refs)
43  { // construct with ref count
44  }
_STD codecvt< _Elem, char, _Statype > _Mybase
Definition: utf16:34
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
47  { // destroy the object
48  }

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

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