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

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_jis_0208 (size_t _Refs=0)
 
virtual ~codecvt_jis_0208 () _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 = 0x7e7e>
typedef char stdext::cvt::codecvt_jis_0208< _Elem, _Maxcode >::_Byte
template<class _Elem , unsigned long _Maxcode = 0x7e7e>
typedef _STD codecvt<_Elem, char, _Statype> stdext::cvt::codecvt_jis_0208< _Elem, _Maxcode >::_Mybase
template<class _Elem , unsigned long _Maxcode = 0x7e7e>
typedef _Byte stdext::cvt::codecvt_jis_0208< _Elem, _Maxcode >::extern_type
template<class _Elem , unsigned long _Maxcode = 0x7e7e>
typedef _Elem stdext::cvt::codecvt_jis_0208< _Elem, _Maxcode >::intern_type
template<class _Elem , unsigned long _Maxcode = 0x7e7e>
typedef _Mybase::result stdext::cvt::codecvt_jis_0208< _Elem, _Maxcode >::result
template<class _Elem , unsigned long _Maxcode = 0x7e7e>
typedef _Statype stdext::cvt::codecvt_jis_0208< _Elem, _Maxcode >::state_type

Constructor & Destructor Documentation

template<class _Elem , unsigned long _Maxcode = 0x7e7e>
stdext::cvt::codecvt_jis_0208< _Elem, _Maxcode >::codecvt_jis_0208 ( size_t  _Refs = 0)
inlineexplicit
38  : _Mybase(_Refs)
39  { // construct with ref count
40  }
_STD codecvt< _Elem, char, _Statype > _Mybase
Definition: jis_0208:30
template<class _Elem , unsigned long _Maxcode = 0x7e7e>
virtual stdext::cvt::codecvt_jis_0208< _Elem, _Maxcode >::~codecvt_jis_0208 ( )
inlinevirtual
43  { // destroy the object
44  }

Member Function Documentation

template<class _Elem , unsigned long _Maxcode = 0x7e7e>
virtual bool stdext::cvt::codecvt_jis_0208< _Elem, _Maxcode >::do_always_noconv ( ) const
inlineprotectedvirtual
234  { // return true if conversions never change input
235  return (false);
236  }
template<class _Elem , unsigned long _Maxcode = 0x7e7e>
virtual int stdext::cvt::codecvt_jis_0208< _Elem, _Maxcode >::do_encoding ( ) const
inlineprotectedvirtual
244  { // return length of code sequence (from codecvt)
245  return (0); // 0 => varying length
246  }
template<class _Elem , unsigned long _Maxcode = 0x7e7e>
virtual result stdext::cvt::codecvt_jis_0208< _Elem, _Maxcode >::do_in ( _Statype _State,
const _Byte _First1,
const _Byte _Last1,
const _Byte *&  _Mid1,
_Elem *  _First2,
_Elem *  _Last2,
_Elem *&  _Mid2 
) const
inlineprotectedvirtual
50  { // convert bytes [_First1, _Last1) to [_First2, _Last)
51  char *_Pstate = (char *)&_State;
52  result _Ans = _Mybase::partial;
53  _Mid1 = _First1;
54  _Mid2 = _First2;
55 
56  for (; _Mid1 != _Last1 && _Mid2 != _Last2; )
57  { // convert a multibyte sequence
58  unsigned char _By = (unsigned char)*_Mid1;
59  unsigned short _Ch;
60 
61  if (_By != _ESC_CODE)
62  ;
63  else if (_Last1 - _Mid1 < 4)
64  break;
65  else if (_Mid1[1] == '('
66  && (_Mid1[2] == 'B' || _Mid1[2] == 'J')
67  && _Mid1[3] != _ESC_CODE)
68  { // shift to 1-byte mode
69  _By = *(_Mid1 += 3);
70  *_Pstate = 0;
71  continue;
72  }
73  else if (_Mid1[1] == '$'
74  && (_Mid1[2] == 'B' || _Mid1[2] == '@'))
75  if (_Last1 - _Mid1 < 5)
76  break; // not enough bytes for escape plus 2-byte code
77  else
78  { // enough bytes, shift and convert
79  _By = *(_Mid1 += 3);
80  *_Pstate = 1;
81  continue;
82  }
83  else
84  return (_Mybase::error); // bad escape sequence
85 
86  _Ch = _By;
87  if (*_Pstate == 0)
88  ;
89  else if (_By < 0x21 || 0x7e < _By)
90  return (_Mybase::error); // bad first byte
91  else if (_Last1 - _Mid1 < 2)
92  break;
93  else if ((_By = *++_Mid1) < 0x21 || 0x7e < _By)
94  return (_Mybase::error); // bad second byte
95  else
96  _Ch = (unsigned short)(_Ch << 8 | _By);
97 
98  if (_Maxcode < _Ch)
99  return (_Mybase::error); // code too large
100  ++_Mid1;
101  *_Mid2++ = (_Elem)_Ch;
102  _Ans = _Mybase::ok;
103  }
104 
105  return (_Ans);
106  }
_Mybase::result result
Definition: jis_0208:31
_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
unsigned char
Definition: mbstring.h:107
#define _ESC_CODE
Definition: jis_0208:21
template<class _Elem , unsigned long _Maxcode = 0x7e7e>
virtual int stdext::cvt::codecvt_jis_0208< _Elem, _Maxcode >::do_length ( _Statype _State,
const _Byte _First1,
const _Byte _Last1,
size_t  _Count 
) const
inlineprotectedvirtual
203  { // return min(_Count, converted length of bytes [_First1, _Last1))
204  size_t _Wchars = 0;
205  _Statype _Mystate = _State;
206 
207  for (; _Wchars < _Count && _First1 != _Last1; )
208  { // convert another wide character
209  const _Byte *_Mid1;
210  _Elem *_Mid2;
211  _Elem _Ch;
212 
213  switch (do_in(_Mystate, _First1, _Last1, _Mid1,
214  &_Ch, &_Ch + 1, _Mid2))
215  { // test result of single wide-char conversion
216  case _Mybase::noconv:
217  return ((int)(_Wchars + (_Last1 - _First1)));
218 
219  case _Mybase::ok:
220  if (_Mid2 == &_Ch + 1)
221  ++_Wchars; // replacement do_in might not convert one
222  _First1 = _Mid1;
223  break;
224 
225  default:
226  return ((int)_Wchars); // error or partial
227  }
228  }
229 
230  return ((int)_Wchars);
231  }
char _Byte
Definition: jis_0208:32
_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
virtual result do_in(_Statype &_State, const _Byte *_First1, const _Byte *_Last1, const _Byte *&_Mid1, _Elem *_First2, _Elem *_Last2, _Elem *&_Mid2) const
Definition: jis_0208:47
_Diff _Count
Definition: algorithm:1941
_CSTD mbstate_t _Statype
Definition: codecvt:28
template<class _Elem , unsigned long _Maxcode = 0x7e7e>
virtual int stdext::cvt::codecvt_jis_0208< _Elem, _Maxcode >::do_max_length ( ) const
inlineprotectedvirtual
239  { // return maximum length required for a conversion
240  return (5);
241  }
template<class _Elem , unsigned long _Maxcode = 0x7e7e>
virtual result stdext::cvt::codecvt_jis_0208< _Elem, _Maxcode >::do_out ( _Statype _State,
const _Elem *  _First1,
const _Elem *  _Last1,
const _Elem *&  _Mid1,
_Byte _First2,
_Byte _Last2,
_Byte *&  _Mid2 
) const
inlineprotectedvirtual
111  { // convert [_First1, _Last1) to bytes [_First2, _Last)
112  char *_Pstate = (char *)&_State;
113  _Mid1 = _First1;
114  _Mid2 = _First2;
115 
116  for (; _Mid1 != _Last1 && _Mid2 != _Last2; )
117  { // convert and put a wide char
118  unsigned long _Ch = (unsigned long)*_Mid1;
119 
120  if (_Maxcode < _Ch)
121  return (_Mybase::error);
122 
123  if (_Ch <= 0xff)
124  { // put a 1-byte code
125  if (_Ch == _ESC_CODE)
126  return (_Mybase::error); // can't output bald ESC
127  else if (*_Pstate == 0)
128  ; // already in proper state
129  else if (_Last2 - _Mid2 < 4)
130  break;
131  else
132  { // put shift to 1-byte state
133  *_Mid2++ = _ESC_CODE;
134  *_Mid2++ = '(';
135  *_Mid2++ = 'B';
136  *_Pstate = 0;
137  }
138  *_Mid2++ = (_Byte)_Ch;
139  }
140  else
141  { // put a 2-byte code
142  if (*_Pstate != 0)
143  { // already in proper state, check room
144  if (_Last2 - _Mid2 < 2)
145  break;
146  }
147  else if (_Last2 - _Mid2 < 5)
148  break;
149  else
150  { // put shift to 2-byte state
151  *_Mid2++ = _ESC_CODE;
152  *_Mid2++ = '$';
153  *_Mid2++ = 'B';
154  *_Pstate = 1;
155  }
156 
157  unsigned char _By = (unsigned char)(_Ch >> 8);
158 
159  if (_By < 0x21 || 0x7e < _By)
160  return (_Mybase::error); // bad first byte
161  *_Mid2++ = (_Byte)_By;
162 
163  _By = (unsigned char)_Ch;
164  if (_By < 0x21 || 0x7e < _By)
165  return (_Mybase::error); // bad first byte
166  *_Mid2++ = (_Byte)_By;
167  }
168  ++_Mid1;
169  }
170  return (_First1 == _Mid1 ? _Mybase::partial : _Mybase::ok);
171  }
char _Byte
Definition: jis_0208:32
_In_ long
Definition: corecrt_wstdlib.h:88
_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
unsigned char
Definition: mbstring.h:107
#define _ESC_CODE
Definition: jis_0208:21
template<class _Elem , unsigned long _Maxcode = 0x7e7e>
virtual result stdext::cvt::codecvt_jis_0208< _Elem, _Maxcode >::do_unshift ( _Statype _State,
_Byte _First2,
_Byte ,
_Byte *&  _Mid2 
) const
inlineprotectedvirtual
175  { // generate bytes to return to default shift state
176  char *_Pstate = (char *)&_State;
177 
178  _Mid2 = _First2;
179  switch (*_Pstate)
180  {
181  case 1: // need to home, put first of three bytes
182  *_Pstate = 2;
183  *_Mid2++ = _ESC_CODE;
184  break;
185 
186  case 2: // put second of three bytes
187  *_Pstate = 3;
188  *_Mid2++ = '(';
189  break;
190 
191  case 3: // put third of three bytes
192  *_Pstate = 0;
193  *_Mid2++ = 'B';
194 
195  case 0: // fall through
196  return (_Mybase::ok);
197  }
198  return (_Mybase::partial);
199  }
_In_ size_t _Deref_pre_opt_z_ char const _In_ size_t _Inout_ mbstate_t * _State
Definition: wchar.h:78
#define _ESC_CODE
Definition: jis_0208:21

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