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
37  : _Mybase(_Refs)
38  { // construct with ref count
39  }
_STD codecvt< _Elem, char, _Statype > _Mybase
Definition: jis_0208:29
template<class _Elem , unsigned long _Maxcode = 0x7e7e>
virtual stdext::cvt::codecvt_jis_0208< _Elem, _Maxcode >::~codecvt_jis_0208 ( )
inlinevirtual
42  { // destroy the object
43  }

Member Function Documentation

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

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