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
106  : _Mybase(_Refs)
107  { // construct with ref count
108  }
_STD codecvt< _Elem, char, _Statype > _Mybase
Definition: xjis:98
template<class _Elem , unsigned long _Maxcode = 0xffff>
virtual stdext::cvt::codecvt_jis< _Elem, _Maxcode >::~codecvt_jis ( )
inlinevirtual
111  { // destroy the object
112  }

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

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