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
44  : _Mybase(_Refs)
45  { // construct with ref count
46  }
_STD codecvt< _Elem, char, _Statype > _Mybase
Definition: utf8_utf16:33
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
50  { // destroy the object
51  }

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

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