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

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

Member Typedef Documentation

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

Constructor & Destructor Documentation

template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0, class _Statype = _Mbstatype>
stdext::cvt::codecvt_utf8_utf16< _Elem, _Maxcode, _Mode, _Statype >::codecvt_utf8_utf16 ( size_t  _Refs = 0)
inlineexplicit
45  : _Mybase(_Refs)
46  { // construct with ref count
47  }
_STD codecvt< _Elem, char, _Statype > _Mybase
Definition: utf8_utf16:34
template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0, class _Statype = _Mbstatype>
virtual stdext::cvt::codecvt_utf8_utf16< _Elem, _Maxcode, _Mode, _Statype >::~codecvt_utf8_utf16 ( )
inlinevirtual
51  { // destroy the object
52  }

Member Function Documentation

template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0, class _Statype = _Mbstatype>
virtual bool stdext::cvt::codecvt_utf8_utf16< _Elem, _Maxcode, _Mode, _Statype >::do_always_noconv ( ) const
inlineprotectedvirtual
274  { // return true if conversions never change input
275  return (false);
276  }
template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0, class _Statype = _Mbstatype>
virtual int stdext::cvt::codecvt_utf8_utf16< _Elem, _Maxcode, _Mode, _Statype >::do_encoding ( ) const
inlineprotectedvirtual
286  { // return length of code sequence (from codecvt)
287  return (0); // 0 => varying length
288  }
template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0, class _Statype = _Mbstatype>
virtual result stdext::cvt::codecvt_utf8_utf16< _Elem, _Maxcode, _Mode, _Statype >::do_in ( _Statype _State,
const _Byte _First1,
const _Byte _Last1,
const _Byte *&  _Mid1,
_Elem *  _First2,
_Elem *  _Last2,
_Elem *&  _Mid2 
) const
inlineprotectedvirtual
58  { // convert bytes [_First1, _Last1) to [_First2, _Last2)
59  unsigned short *_Pstate = (unsigned short *)&_State;
60  _Mid1 = _First1;
61  _Mid2 = _First2;
62 
63  for (; _Mid1 != _Last1 && _Mid2 != _Last2; )
64  { // convert a multibyte sequence
65  unsigned char _By = (unsigned char)*_Mid1;
66  unsigned long _Ch;
67  int _Nextra, _Nskip;
68 
69  if (*_Pstate <= 1)
70  ; // no leftover word
71  else if (_By < 0x80 || 0xc0 <= _By)
72  return (_Mybase::error); // not continuation byte
73  else
74  { // deliver second half of two-word value
75  ++_Mid1;
76  *_Mid2++ = (_Elem)(*_Pstate | (_By & 0x3f));
77  *_Pstate = 1;
78  continue;
79  }
80 
81  if (_By < 0x80)
82  _Ch = _By, _Nextra = 0;
83  else if (_By < 0xc0)
84  { // 0x80-0xdf not first byte
85  ++_Mid1;
86  return (_Mybase::error);
87  }
88  else if (_By < 0xe0)
89  _Ch = _By & 0x1f, _Nextra = 1;
90  else if (_By < 0xf0)
91  _Ch = _By & 0x0f, _Nextra = 2;
92  else if (_By < 0xf8)
93  _Ch = _By & 0x07, _Nextra = 3;
94  else
95  _Ch = _By & 0x03, _Nextra = _By < 0xfc ? 4 : 5;
96 
97  _Nskip = _Nextra < 3 ? 0 : 1; // leave a byte for 2nd word
98  _First1 = _Mid1; // roll back point
99 
100  if (_Nextra == 0)
101  ++_Mid1;
102  else if (_Last1 - _Mid1 < _Nextra + 1 - _Nskip)
103  break; // not enough input
104  else
105  for (++_Mid1; _Nskip < _Nextra; --_Nextra, ++_Mid1)
106  if ((_By = (unsigned char)*_Mid1) < 0x80 || 0xc0 <= _By)
107  return (_Mybase::error); // not continuation byte
108  else
109  _Ch = _Ch << 6 | (_By & 0x3f);
110  if (0 < _Nskip)
111  _Ch <<= 6; // get last byte on next call
112 
113  if ((_Maxcode < 0x10ffff ? _Maxcode : 0x10ffff) < _Ch)
114  return (_Mybase::error); // value too large
115  else if (0xffff < _Ch)
116  { // deliver first half of two-word value, save second word
117  unsigned short _Ch0 =
118  (unsigned short)(0xd800 | (_Ch >> 10) - 0x0040);
119 
120  *_Mid2++ = (_Elem)_Ch0;
121  *_Pstate = (unsigned short)(0xdc00 | (_Ch & 0x03ff));
122  continue;
123  }
124 
125  if (_Nskip == 0)
126  ;
127  else if (_Mid1 == _Last1)
128  { // not enough bytes, noncanonical value
129  _Mid1 = _First1;
130  break;
131  }
132  else if ((_By = (unsigned char)*_Mid1++) < 0x80 || 0xc0 <= _By)
133  return (_Mybase::error); // not continuation byte
134  else
135  _Ch |= _By & 0x3f; // complete noncanonical value
136 
137  if (*_Pstate == 0)
138  { // first time, maybe look for and consume header
139  *_Pstate = 1;
140 
141  if ((_Mode & _STD consume_header) != 0 && _Ch == 0xfeff)
142  { // drop header and retry
143  result _Ans = do_in(_State, _Mid1, _Last1, _Mid1,
144  _First2, _Last2, _Mid2);
145 
146  if (_Ans == _Mybase::partial)
147  { // roll back header determination
148  *_Pstate = 0;
149  _Mid1 = _First1;
150  }
151  return (_Ans);
152  }
153  }
154 
155  *_Mid2++ = (_Elem)_Ch;
156  }
157 
158  return (_First1 == _Mid1 ? _Mybase::partial : _Mybase::ok);
159  }
Definition: codecvt:24
_Check_return_ _In_ wchar_t _Ch
Definition: vcruntime_string.h:89
_Mybase::result result
Definition: utf8_utf16:35
_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
virtual result do_in(_Statype &_State, const _Byte *_First1, const _Byte *_Last1, const _Byte *&_Mid1, _Elem *_First2, _Elem *_Last2, _Elem *&_Mid2) const
Definition: utf8_utf16:55
template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0, class _Statype = _Mbstatype>
virtual int stdext::cvt::codecvt_utf8_utf16< _Elem, _Maxcode, _Mode, _Statype >::do_length ( _Statype _State,
const _Byte _First1,
const _Byte _Last1,
size_t  _Count 
) const
inlineprotectedvirtual
243  { // return min(_Count, converted length of bytes [_First1, _Last1))
244  size_t _Wchars = 0;
245  _Statype _Mystate = _State;
246 
247  for (; _Wchars < _Count && _First1 != _Last1; )
248  { // convert another wide character
249  const _Byte *_Mid1;
250  _Elem *_Mid2;
251  _Elem _Ch;
252 
253  switch (do_in(_Mystate, _First1, _Last1, _Mid1,
254  &_Ch, &_Ch + 1, _Mid2))
255  { // test result of single wide-char conversion
256  case _Mybase::noconv:
257  return ((int)(_Wchars + (_Last1 - _First1)));
258 
259  case _Mybase::ok:
260  if (_Mid2 == &_Ch + 1)
261  ++_Wchars; // replacement do_in might not convert one
262  _First1 = _Mid1;
263  break;
264 
265  default:
266  return ((int)_Wchars); // error or partial
267  }
268  }
269 
270  return ((int)_Wchars);
271  }
_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: utf8_utf16:36
virtual result do_in(_Statype &_State, const _Byte *_First1, const _Byte *_Last1, const _Byte *&_Mid1, _Elem *_First2, _Elem *_Last2, _Elem *&_Mid2) const
Definition: utf8_utf16:55
_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, class _Statype = _Mbstatype>
virtual int stdext::cvt::codecvt_utf8_utf16< _Elem, _Maxcode, _Mode, _Statype >::do_max_length ( ) const
inlineprotectedvirtual
279  { // return maximum length required for a conversion
280  return ((_Mode & _STD consume_header) != 0 ? 9 // header + max input
281  : (_Mode & _STD generate_header) != 0 ? 7 // header + max output
282  : 6); // 6-byte max input sequence, no 3-byte header
283  }
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, class _Statype = _Mbstatype>
virtual result stdext::cvt::codecvt_utf8_utf16< _Elem, _Maxcode, _Mode, _Statype >::do_out ( _Statype _State,
const _Elem *  _First1,
const _Elem *  _Last1,
const _Elem *&  _Mid1,
_Byte _First2,
_Byte _Last2,
_Byte *&  _Mid2 
) const
inlineprotectedvirtual
164  { // convert [_First1, _Last1) to bytes [_First2, _Last)
165  unsigned short *_Pstate = (unsigned short *)&_State;
166  _Mid1 = _First1;
167  _Mid2 = _First2;
168 
169  for (; _Mid1 != _Last1 && _Mid2 != _Last2; )
170  { // convert and put a wide char
171  unsigned long _Ch;
172  unsigned short _Ch1 = (unsigned short)*_Mid1;
173  bool _Save = false;
174 
175  if (1 < *_Pstate)
176  { // get saved MS 11 bits from *_Pstate
177  if (_Ch1 < 0xdc00 || 0xe000 <= _Ch1)
178  return (_Mybase::error); // bad second word
179  _Ch = (*_Pstate << 10) | (_Ch1 - 0xdc00);
180  }
181  else if (0xd800 <= _Ch1 && _Ch1 < 0xdc00)
182  { // get new first word
183  _Ch = (_Ch1 - 0xd800 + 0x0040) << 10;
184  _Save = true; // put only first byte, rest with second word
185  }
186  else
187  _Ch = _Ch1; // not first word, just put it
188 
189  _Byte _By;
190  int _Nextra;
191 
192  if (_Ch < 0x0080)
193  _By = (_Byte)_Ch, _Nextra = 0;
194  else if (_Ch < 0x0800)
195  _By = (_Byte)(0xc0 | _Ch >> 6), _Nextra = 1;
196  else if (_Ch < 0x10000)
197  _By = (_Byte)(0xe0 | _Ch >> 12), _Nextra = 2;
198  else
199  _By = (_Byte)(0xf0 | _Ch >> 18), _Nextra = 3;
200 
201  int _Nput = _Nextra < 3 ? _Nextra + 1 : _Save ? 1 : 3;
202 
203  if (_Last2 - _Mid2 < _Nput)
204  break; // not enough room, even without header
205  else if (*_Pstate != 0 || (_Mode & _STD generate_header) == 0)
206  ; // no header to put
207  else if (_Last2 - _Mid2 < 3 + _Nput)
208  break; // not enough room for both
209  else
210  { // prepend header
211  *_Mid2++ = (_Byte)(unsigned char)0xef;
212  *_Mid2++ = (_Byte)(unsigned char)0xbb;
213  *_Mid2++ = (_Byte)(unsigned char)0xbf;
214  }
215 
216  ++_Mid1;
217  if (_Save || _Nextra < 3)
218  { // put first byte of sequence, if not already put
219  *_Mid2++ = _By;
220  --_Nput;
221  }
222  for (; 0 < _Nput; --_Nput)
223  *_Mid2++ = (_Byte)((_Ch >> 6 * --_Nextra & 0x3f) | 0x80);
224 
225  *_Pstate = (unsigned short)(_Save ? _Ch >> 10 : 1);
226  }
227 
228  return (_First1 == _Mid1 ? _Mybase::partial : _Mybase::ok);
229  }
Definition: codecvt:25
_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: utf8_utf16:36
template<class _Elem , unsigned long _Maxcode = 0x10ffff, _STD codecvt_mode _Mode = (_STD codecvt_mode)0, class _Statype = _Mbstatype>
virtual result stdext::cvt::codecvt_utf8_utf16< _Elem, _Maxcode, _Mode, _Statype >::do_unshift ( _Statype _State,
_Byte _First2,
_Byte ,
_Byte *&  _Mid2 
) const
inlineprotectedvirtual
233  { // generate bytes to return to default shift state
234  unsigned short *_Pstate = (unsigned short *)&_State;
235  _Mid2 = _First2;
236 
237  return (1 < *_Pstate
238  ? _Mybase::error : _Mybase::ok); // fail if trailing first word
239  }
_In_ size_t _Deref_pre_opt_z_ char const _In_ size_t _Inout_ mbstate_t * _State
Definition: wchar.h:78

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