STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Types | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | List of all members
stdext::cvt::codecvt_jis< _Elem, _Maxcode > Class Template Reference
Inheritance diagram for stdext::cvt::codecvt_jis< _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 (size_t _Refs=0)
 
virtual ~codecvt_jis () _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()
 

Private Types

typedef _tab_jis< int_Table
 

Private Member Functions

bool _Jis_to_ucs (unsigned short &_Ch) const
 
bool _Ucs_to_jis (unsigned short &_Ch) const
 

Member Typedef Documentation

template<class _Elem , unsigned long _Maxcode = 0xffff>
typedef char stdext::cvt::codecvt_jis< _Elem, _Maxcode >::_Byte
template<class _Elem , unsigned long _Maxcode = 0xffff>
typedef _STD codecvt<_Elem, char, _Statype> stdext::cvt::codecvt_jis< _Elem, _Maxcode >::_Mybase
template<class _Elem , unsigned long _Maxcode = 0xffff>
typedef _tab_jis<int> stdext::cvt::codecvt_jis< _Elem, _Maxcode >::_Table
private
template<class _Elem , unsigned long _Maxcode = 0xffff>
typedef _Byte stdext::cvt::codecvt_jis< _Elem, _Maxcode >::extern_type
template<class _Elem , unsigned long _Maxcode = 0xffff>
typedef _Elem stdext::cvt::codecvt_jis< _Elem, _Maxcode >::intern_type
template<class _Elem , unsigned long _Maxcode = 0xffff>
typedef _Mybase::result stdext::cvt::codecvt_jis< _Elem, _Maxcode >::result
template<class _Elem , unsigned long _Maxcode = 0xffff>
typedef _Statype stdext::cvt::codecvt_jis< _Elem, _Maxcode >::state_type

Constructor & Destructor Documentation

template<class _Elem , unsigned long _Maxcode = 0xffff>
stdext::cvt::codecvt_jis< _Elem, _Maxcode >::codecvt_jis ( size_t  _Refs = 0)
inlineexplicit
107  : _Mybase(_Refs)
108  { // construct with ref count
109  }
_STD codecvt< _Elem, char, _Statype > _Mybase
Definition: xjis:99
template<class _Elem , unsigned long _Maxcode = 0xffff>
virtual stdext::cvt::codecvt_jis< _Elem, _Maxcode >::~codecvt_jis ( )
inlinevirtual
112  { // destroy the object
113  }

Member Function Documentation

template<class _Elem , unsigned long _Maxcode = 0xffff>
bool stdext::cvt::codecvt_jis< _Elem, _Maxcode >::_Jis_to_ucs ( unsigned short &  _Ch) const
inlineprivate
35  { // convert _Ch from JIS-X0208 to UCS-2
36  if (_Ch < _Table::_Nlow)
37  ; // map byte to same wide value
38  else if (_Ch < 0x100)
39  { // map a one-byte code
40  if ((_Ch = _Table::_Btw[_Ch - _Table::_Nlow]) == 0)
41  return (false); // no defined mapping for byte
42  }
43  else
44  { // search for a valid mapping
45  unsigned long _Lo = 0;
46  unsigned long _Hi = sizeof (_Table::_Dbvalid)
47  / sizeof (_Table::_Dbvalid[0]);
48 
49  for (; _Lo < _Hi; )
50  { // test midpoint of remaining interval
51  unsigned long _Mid = (_Hi + _Lo) / 2;
52 
53  if (_Ch < _Table::_Dbvalid[_Mid])
54  _Hi = _Mid;
55  else if (_Ch == _Table::_Dbvalid[_Mid])
56  { // found the code, map it
57  _Ch = _Table::_Dbtw[_Mid];
58  return (true);
59  }
60  else
61  _Lo = _Mid + 1;
62  }
63  return (false);
64  }
65  return (true);
66  }
static const unsigned short _Dbvalid[0x1adf]
Definition: jis:83
static const unsigned short _Dbtw[0x1adf]
Definition: jis:84
_Check_return_ _In_ wchar_t _Ch
Definition: vcruntime_string.h:89
static const unsigned short _Btw[0xa4]
Definition: jis:82
template<class _Elem , unsigned long _Maxcode = 0xffff>
bool stdext::cvt::codecvt_jis< _Elem, _Maxcode >::_Ucs_to_jis ( unsigned short &  _Ch) const
inlineprivate
69  { // convert _Ch from UCS-2 to JIS-X0208
70  if (_Ch < _Table::_Nlow || (_Ch < 0x100
72  ; // map wide to same byte value
73  else
74  { // search for a valid mapping
75  unsigned long _Lo = 0;
76  unsigned long _Hi = sizeof (_Table::_Wvalid)
77  / sizeof (_Table::_Wvalid[0]);
78 
79  for (; _Lo < _Hi; )
80  { // test midpoint of remaining interval
81  unsigned long _Mid = (_Hi + _Lo) / 2;
82 
83  if (_Ch < _Table::_Wvalid[_Mid])
84  _Hi = _Mid;
85  else if (_Ch == _Table::_Wvalid[_Mid])
86  { // found the code, map it
87  _Ch = _Table::_Wtb[_Mid];
88  return (true);
89  }
90  else
91  _Lo = _Mid + 1;
92  }
93  return (false);
94  }
95  return (true);
96  }
_Check_return_ _In_ wchar_t _Ch
Definition: vcruntime_string.h:89
static const unsigned short _Wvalid[0x1b20]
Definition: jis:85
static const unsigned short _Btw[0xa4]
Definition: jis:82
static const unsigned short _Wtb[0x1b20]
Definition: jis:86
template<class _Elem , unsigned long _Maxcode = 0xffff>
virtual bool stdext::cvt::codecvt_jis< _Elem, _Maxcode >::do_always_noconv ( ) const
inlineprotectedvirtual
306  { // return true if conversions never change input
307  return (false);
308  }
template<class _Elem , unsigned long _Maxcode = 0xffff>
virtual int stdext::cvt::codecvt_jis< _Elem, _Maxcode >::do_encoding ( ) const
inlineprotectedvirtual
316  { // return length of code sequence (from codecvt)
317  return (0); // 0 => varying length
318  }
template<class _Elem , unsigned long _Maxcode = 0xffff>
virtual result stdext::cvt::codecvt_jis< _Elem, _Maxcode >::do_in ( _Statype _State,
const _Byte _First1,
const _Byte _Last1,
const _Byte *&  _Mid1,
_Elem *  _First2,
_Elem *  _Last2,
_Elem *&  _Mid2 
) const
inlineprotectedvirtual
119  { // convert bytes [_First1, _Last1) to [_First2, _Last)
120  unsigned long _Maxc = _Maxcode; // to quiet warnings
121  char *_Pstate = (char *)&_State;
122  result _Ans = _Mybase::partial;
123 
124  _Mid1 = _First1;
125  _Mid2 = _First2;
126  for (; _Mid1 != _Last1 && _Mid2 != _Last2; )
127  { // convert a multibyte sequence
128  unsigned char _By = (unsigned char)*_Mid1;
129  unsigned short _Ch;
130 
131  if (_By != _ESC_CODE)
132  ;
133  else if (_Last1 - _Mid1 < 4)
134  break;
135  else if (_Mid1[1] == '('
136  && (_Mid1[2] == 'B' || _Mid1[2] == 'J')
137  && _Mid1[3] != _ESC_CODE)
138  { // shift to 1-byte mode
139  _By = *(_Mid1 += 3);
140  *_Pstate = 0;
141  continue;
142  }
143  else if (_Mid1[1] == '$'
144  && (_Mid1[2] == 'B' || _Mid1[2] == '@'))
145  if (_Last1 - _Mid1 < 5)
146  break; // not enough bytes for escape plus 2-byte code
147  else
148  { // enough bytes, shift and convert
149  _By = *(_Mid1 += 3);
150  *_Pstate = 1;
151  continue;
152  }
153  else
154  return (_Mybase::error); // bad escape sequence
155 
156  _Ch = _By;
157  if (*_Pstate == 0)
158  ;
159  else if (_By < 0x21 || 0x7e < _By)
160  return (_Mybase::error); // bad first byte
161  else if (_Last1 - _Mid1 < 2)
162  break;
163  else if ((_By = *++_Mid1) < 0x21 || 0x7e < _By)
164  return (_Mybase::error); // bad second byte
165  else
166  _Ch = (unsigned short)(_Ch << 8 | _By);
167 
168  if (!_Jis_to_ucs(_Ch) || _Maxc < _Ch)
169  return (_Mybase::error); // code too large
170  ++_Mid1;
171  *_Mid2++ = (_Elem)_Ch;
172  _Ans = _Mybase::ok;
173  }
174 
175  return (_Ans);
176  }
_Mybase::result result
Definition: xjis:100
_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
bool _Jis_to_ucs(unsigned short &_Ch) const
Definition: xjis:34
#define _ESC_CODE
Definition: xjis:24
template<class _Elem , unsigned long _Maxcode = 0xffff>
virtual int stdext::cvt::codecvt_jis< _Elem, _Maxcode >::do_length ( _Statype _State,
const _Byte _First1,
const _Byte _Last1,
size_t  _Count 
) const
inlineprotectedvirtual
275  { // return min(_Count, converted length of bytes [_First1, _Last1))
276  size_t _Wchars = 0;
277  _Statype _Mystate = _State;
278 
279  for (; _Wchars < _Count && _First1 != _Last1; )
280  { // convert another wide character
281  const _Byte *_Mid1;
282  _Elem *_Mid2;
283  _Elem _Ch;
284 
285  switch (do_in(_Mystate, _First1, _Last1, _Mid1,
286  &_Ch, &_Ch + 1, _Mid2))
287  { // test result of single wide-char conversion
288  case _Mybase::noconv:
289  return ((int)(_Wchars + (_Last1 - _First1)));
290 
291  case _Mybase::ok:
292  if (_Mid2 == &_Ch + 1)
293  ++_Wchars; // replacement do_in might not convert one
294  _First1 = _Mid1;
295  break;
296 
297  default:
298  return ((int)_Wchars); // error or partial
299  }
300  }
301 
302  return ((int)_Wchars);
303  }
char _Byte
Definition: xjis:101
_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
_Diff _Count
Definition: algorithm:1941
virtual result do_in(_Statype &_State, const _Byte *_First1, const _Byte *_Last1, const _Byte *&_Mid1, _Elem *_First2, _Elem *_Last2, _Elem *&_Mid2) const
Definition: xjis:116
_CSTD mbstate_t _Statype
Definition: codecvt:28
template<class _Elem , unsigned long _Maxcode = 0xffff>
virtual int stdext::cvt::codecvt_jis< _Elem, _Maxcode >::do_max_length ( ) const
inlineprotectedvirtual
311  { // return maximum length required for a conversion
312  return (5);
313  }
template<class _Elem , unsigned long _Maxcode = 0xffff>
virtual result stdext::cvt::codecvt_jis< _Elem, _Maxcode >::do_out ( _Statype _State,
const _Elem *  _First1,
const _Elem *  _Last1,
const _Elem *&  _Mid1,
_Byte _First2,
_Byte _Last2,
_Byte *&  _Mid2 
) const
inlineprotectedvirtual
181  { // convert [_First1, _Last1) to bytes [_First2, _Last)
182  unsigned long _Maxc = _Maxcode; // to quiet warnings
183  char *_Pstate = (char *)&_State;
184 
185  _Mid1 = _First1;
186  _Mid2 = _First2;
187  for (; _Mid1 != _Last1 && _Mid2 != _Last2; )
188  { // convert and put a wide char
189  unsigned long _Uch = (unsigned long)*_Mid1;
190  unsigned short _Ch = (unsigned short)_Uch;
191 
192  if (_Maxc < _Ch || !_Ucs_to_jis(_Ch))
193  return (_Mybase::error);
194 
195  if (_Ch <= 0xff)
196  { // put a 1-byte code
197  if (_Ch == _ESC_CODE)
198  return (_Mybase::error); // can't output bald ESC
199  else if (*_Pstate == 0)
200  ; // already in proper state
201  else if (_Last2 - _Mid2 < 4)
202  break;
203  else
204  { // put shift to 1-byte state
205  *_Mid2++ = _ESC_CODE;
206  *_Mid2++ = '(';
207  *_Mid2++ = 'B';
208  *_Pstate = 0;
209  }
210  *_Mid2++ = (_Byte)_Ch;
211  }
212  else
213  { // put a 2-byte code
214  if (*_Pstate != 0)
215  { // already in proper state, check room
216  if (_Last2 - _Mid2 < 2)
217  break;
218  }
219  else if (_Last2 - _Mid2 < 5)
220  break;
221  else
222  { // put shift to 2-byte state
223  *_Mid2++ = _ESC_CODE;
224  *_Mid2++ = '$';
225  *_Mid2++ = 'B';
226  *_Pstate = 1;
227  }
228 
229  unsigned char _By = (unsigned char)(_Ch >> 8);
230 
231  if (_By < 0x21 || 0x7e < _By)
232  return (_Mybase::error); // bad first byte
233  *_Mid2++ = (_Byte)_By;
234 
235  _By = (unsigned char)_Ch;
236  if (_By < 0x21 || 0x7e < _By)
237  return (_Mybase::error); // bad first byte
238  *_Mid2++ = (_Byte)_By;
239  }
240  ++_Mid1;
241  }
242  return (_First1 == _Mid1 ? _Mybase::partial : _Mybase::ok);
243  }
char _Byte
Definition: xjis:101
_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
bool _Ucs_to_jis(unsigned short &_Ch) const
Definition: xjis:68
#define _ESC_CODE
Definition: xjis:24
template<class _Elem , unsigned long _Maxcode = 0xffff>
virtual result stdext::cvt::codecvt_jis< _Elem, _Maxcode >::do_unshift ( _Statype _State,
_Byte _First2,
_Byte ,
_Byte *&  _Mid2 
) const
inlineprotectedvirtual
247  { // generate bytes to return to default shift state
248  char *_Pstate = (char *)&_State;
249 
250  _Mid2 = _First2;
251  switch (*_Pstate)
252  {
253  case 1: // need to home, put first of three bytes
254  *_Pstate = 2;
255  *_Mid2++ = _ESC_CODE;
256  break;
257 
258  case 2: // put second of three bytes
259  *_Pstate = 3;
260  *_Mid2++ = '(';
261  break;
262 
263  case 3: // put third of three bytes
264  *_Pstate = 0;
265  *_Mid2++ = 'B';
266 
267  case 0: // fall through
268  return (_Mybase::ok);
269  }
270  return (_Mybase::partial);
271  }
_In_ size_t _Deref_pre_opt_z_ char const _In_ size_t _Inout_ mbstate_t * _State
Definition: wchar.h:78
#define _ESC_CODE
Definition: xjis:24

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