📄 xlocale
字号:
}
virtual result __CLR_OR_THIS_CALL do_out(_Statype&,
const _Elem *_First1, const _Elem *, const _Elem *& _Mid1,
_Byte *_First2, _Byte *, _Byte *& _Mid2) const
{ // convert [_First1, _Last1) to bytes [_First2, _Last)
_Mid1 = _First1, _Mid2 = _First2;
return (noconv); // convert nothing
}
virtual result __CLR_OR_THIS_CALL do_unshift(_Statype&,
_Byte *_First2, _Byte *, _Byte *&_Mid2) const
{ // generate bytes to return to default shift state
_Mid2 = _First2;
return (noconv); // convert nothing
}
virtual int __CLR_OR_THIS_CALL do_length(const _Statype&, const _Byte *_First1,
const _Byte *_Last1, size_t _Count) const
{ // return min(_Count, converted length of bytes [_First1, _Last1))
return ((int)(_Count < (size_t)(_Last1 - _First1)
? _Count : _Last1 - _First1)); // assume 1-to-1 conversion
}
};
// STATIC codecvt::id OBJECT
template<class _Elem,
class _Byte,
class _Statype>
__PURE_APPDOMAIN_GLOBAL locale::id codecvt<_Elem, _Byte, _Statype>::id;
#if _HAS_CHAR16_T_LANGUAGE_SUPPORT
// ENUM _Codecvt_mode
enum _Codecvt_mode {
_Consume_header = 4,
_Generate_header = 2
};
// CLASS codecvt<char16_t, char, _Mbstatet>
template<>
class _CRTIMP2_PURE codecvt<char16_t, char, _Mbstatet>
: public codecvt_base
{ // facet for converting between char16_t and UTF-8 byte sequences
public:
typedef codecvt<char16_t, char, _Mbstatet> _Mybase;
typedef char16_t _Elem;
typedef char _Byte;
typedef _Mbstatet _Statype;
typedef _Elem intern_type;
typedef _Byte extern_type;
typedef _Statype state_type;
result __CLR_OR_THIS_CALL in(_Statype& _State,
const _Byte *_First1, const _Byte *_Last1, const _Byte *& _Mid1,
_Elem *_First2, _Elem *_Last2, _Elem *& _Mid2) const
{ // convert bytes [_First1, _Last1) to [_First2, _Last)
return (do_in(_State,
_First1, _Last1, _Mid1, _First2, _Last2, _Mid2));
}
result __CLR_OR_THIS_CALL out(_Statype& _State,
const _Elem *_First1, const _Elem *_Last1, const _Elem *& _Mid1,
_Byte *_First2, _Byte *_Last2, _Byte *& _Mid2) const
{ // convert [_First1, _Last1) to bytes [_First2, _Last)
return (do_out(_State,
_First1, _Last1, _Mid1, _First2, _Last2, _Mid2));
}
result __CLR_OR_THIS_CALL unshift(_Statype& _State,
_Byte *_First2, _Byte *_Last2, _Byte *& _Mid2) const
{ // generate bytes to return to default shift state
return (do_unshift(_State,
_First2, _Last2, _Mid2));
}
int __CLR_OR_THIS_CALL length(const _Statype& _State, const _Byte *_First1,
const _Byte *_Last1, size_t _Count) const
{ // return min(_Count, converted length of bytes [_First1, _Last1))
return (do_length(_State, _First1, _Last1, _Count));
}
__PURE_APPDOMAIN_GLOBAL static locale::id id;
explicit __CLR_OR_THIS_CALL codecvt(size_t _Refs = 0)
: codecvt_base(_Refs), _Maxcode(0x10ffff), _Mode(_Consume_header)
{ // construct from current locale
_BEGIN_LOCINFO(_Lobj)
_Init(_Lobj);
_END_LOCINFO()
}
__CLR_OR_THIS_CALL codecvt(const _Locinfo& _Lobj, size_t _Refs = 0)
: codecvt_base(_Refs), _Maxcode(0x10ffff), _Mode(_Consume_header)
{ // construct from specified locale
_Init(_Lobj);
}
__CLR_OR_THIS_CALL codecvt(const _Locinfo& _Lobj, unsigned long _Maxcode_arg,
_Codecvt_mode _Mode_arg, size_t _Refs = 0)
: codecvt_base(_Refs), _Maxcode(_Maxcode_arg), _Mode(_Mode_arg)
{ // construct from specified locale and parameters
_Init(_Lobj);
}
static size_t __CLRCALL_OR_CDECL _Getcat(const locale::facet **_Ppf = 0,
const locale *_Ploc = 0)
{ // return locale category mask and construct standard facet
if (_Ppf != 0 && *_Ppf == 0)
*_Ppf = _NEW_CRT codecvt<_Elem, _Byte, _Statype>(
_Locinfo(_Ploc->c_str()));
return (_X_CTYPE);
}
protected:
virtual __CLR_OR_THIS_CALL ~codecvt()
{ // destroy the object
}
void __CLR_OR_THIS_CALL _Init(const _Locinfo&)
{ // initialize
}
virtual result __CLR_OR_THIS_CALL do_in(_Statype& _State,
const _Byte *_First1, const _Byte *_Last1, const _Byte *& _Mid1,
_Elem *_First2, _Elem *_Last2, _Elem *& _Mid2) const
{ // convert bytes [_First1, _Last1) to [_First2, _Last2)
unsigned short *_Pstate = (unsigned short *)&_State;
_Mid1 = _First1;
_Mid2 = _First2;
for (; _Mid1 != _Last1 && _Mid2 != _Last2; )
{ // convert a multibyte sequence
unsigned char _By = (unsigned char)*_Mid1;
unsigned long _Ch;
int _Nextra, _Nskip;
if (*_Pstate <= 1)
; // no leftover word
else if (_By < 0x80 || 0xc0 <= _By)
return (_Mybase::error); // not continuation byte
else
{ // deliver second half of two-word value
++_Mid1;
*_Mid2++ = (_Elem)(*_Pstate | _By & 0x3f);
*_Pstate = 1;
continue;
}
if (_By < 0x80)
_Ch = _By, _Nextra = 0;
else if (_By < 0xc0)
{ // 0x80-0xdf not first byte
++_Mid1;
return (_Mybase::error);
}
else if (_By < 0xe0)
_Ch = _By & 0x1f, _Nextra = 1;
else if (_By < 0xf0)
_Ch = _By & 0x0f, _Nextra = 2;
else if (_By < 0xf8)
_Ch = _By & 0x07, _Nextra = 3;
else
_Ch = _By & 0x03, _Nextra = _By < 0xfc ? 4 : 5;
_Nskip = _Nextra < 3 ? 0 : 1; // leave a byte for 2nd word
_First1 = _Mid1; // roll back point
if (_Nextra == 0)
++_Mid1;
else if (_Last1 - _Mid1 < _Nextra + 1 - _Nskip)
break; // not enough input
else
for (++_Mid1; _Nskip < _Nextra; --_Nextra, ++_Mid1)
if ((_By = (unsigned char)*_Mid1) < 0x80 || 0xc0 <= _By)
return (_Mybase::error); // not continuation byte
else
_Ch = _Ch << 6 | _By & 0x3f;
if (0 < _Nskip)
_Ch <<= 6; // get last byte on next call
if ((_Maxcode < 0x10ffff ? _Maxcode : 0x10ffff) < _Ch)
return (_Mybase::error); // value too large
else if (0xffff < _Ch)
{ // deliver first half of two-word value, save second word
unsigned short _Ch0 =
(unsigned short)(0xd800 | (_Ch >> 10) - 0x0040);
*_Mid2++ = (_Elem)_Ch0;
*_Pstate = (unsigned short)(0xdc00 | _Ch & 0x03ff);
continue;
}
if (_Nskip == 0)
;
else if (_Mid1 == _Last1)
{ // not enough bytes, noncanonical value
_Mid1 = _First1;
break;
}
else if ((_By = (unsigned char)*_Mid1++) < 0x80 || 0xc0 <= _By)
return (_Mybase::error); // not continuation byte
else
_Ch |= _By & 0x3f; // complete noncanonical value
if (*_Pstate == 0)
{ // first time, maybe look for and consume header
*_Pstate = 1;
if ((_Mode & _Consume_header) != 0 && _Ch == 0xfeff)
{ // drop header and retry
result _Ans = do_in(_State, _Mid1, _Last1, _Mid1,
_First2, _Last2, _Mid2);
if (_Ans == _Mybase::partial)
{ // roll back header determination
*_Pstate = 0;
_Mid1 = _First1;
}
return (_Ans);
}
}
*_Mid2++ = (_Elem)_Ch;
}
return (_First1 == _Mid1 ? _Mybase::partial : _Mybase::ok);
}
virtual result __CLR_OR_THIS_CALL do_out(_Statype& _State,
const _Elem *_First1, const _Elem *_Last1, const _Elem *& _Mid1,
_Byte *_First2, _Byte *_Last2, _Byte *& _Mid2) const
{ // convert [_First1, _Last1) to bytes [_First2, _Last)
unsigned short *_Pstate = (unsigned short *)&_State;
_Mid1 = _First1;
_Mid2 = _First2;
for (; _Mid1 != _Last1 && _Mid2 != _Last2; )
{ // convert and put a wide char
unsigned long _Ch;
unsigned short _Ch1 = (unsigned short)*_Mid1;
bool _Save = false;
if (1 < *_Pstate)
{ // get saved MS 11 bits from *_Pstate
if (_Ch1 < 0xdc00 || 0xe000 <= _Ch1)
return (_Mybase::error); // bad second word
_Ch = (*_Pstate << 10) | (_Ch1 - 0xdc00);
}
else if (0xd800 <= _Ch1 && _Ch1 < 0xdc00)
{ // get new first word
_Ch = (_Ch1 - 0xd800 + 0x0040) << 10;
_Save = true; // put only first byte, rest with second word
}
else
_Ch = _Ch1; // not first word, just put it
_Byte _By;
int _Nextra;
if (_Ch < 0x0080)
_By = (_Byte)_Ch, _Nextra = 0;
else if (_Ch < 0x0800)
_By = (_Byte)(0xc0 | _Ch >> 6), _Nextra = 1;
else if (_Ch < 0x10000)
_By = (_Byte)(0xe0 | _Ch >> 12), _Nextra = 2;
else
_By = (_Byte)(0xf0 | _Ch >> 18), _Nextra = 3;
int _Nput = _Nextra < 3 ? _Nextra + 1 : _Save ? 1 : 3;
if (_Last2 - _Mid2 < _Nput)
break; // not enough room, even without header
else if (*_Pstate != 0 || (_Mode & _Generate_header) == 0)
; // no header to put
else if (_Last2 - _Mid2 < 3 + _Nput)
break; // not enough room for header + output
else
{ // prepend header
*_Mid2++ = (_Byte)(unsigned char)0xef;
*_Mid2++ = (_Byte)(unsigned char)0xbb;
*_Mid2++ = (_Byte)(unsigned char)0xbf;
}
++_Mid1;
if (_Save || _Nextra < 3)
{ // put first byte of sequence, if not already put
*_Mid2++ = _By;
--_Nput;
}
for (; 0 < _Nput; --_Nput)
*_Mid2++ = (_Byte)(_Ch >> 6 * --_Nextra & 0x3f | 0x80);
*_Pstate = (unsigned short)(_Save ? _Ch >> 10 : 1);
}
return (_First1 == _Mid1 ? _Mybase::partial : _Mybase::ok);
}
virtual result __CLR_OR_THIS_CALL do_unshift(_Statype& _State,
_Byte *_First2, _Byte *, _Byte *& _Mid2) const
{ // generate bytes to return to default shift state
unsigned short *_Pstate = (unsigned short *)&_State;
_Mid2 = _First2;
return (1 < *_Pstate
? _Mybase::error : _Mybase::ok); // fail if trailing first word
}
virtual int __CLR_OR_THIS_CALL do_length(const _Statype& _State, const _Byte *_First1,
const _Byte *_Last1, size_t _Count) const _THROW0()
{ // return min(_Count, converted length of bytes [_First1, _Last1))
size_t _Wchars = 0;
_Statype _Mystate = _State;
for (; _Wchars < _Count && _First1 != _Last1; )
{ // convert another wide character
const _Byte *_Mid1;
_Elem *_Mid2;
_Elem _Ch;
switch (do_in(_Mystate, _First1, _Last1, _Mid1,
&_Ch, &_Ch + 1, _Mid2))
{ // test result of single wide-char conversion
case _Mybase::noconv:
return ((int)(_Wchars + (_Last1 - _First1)));
case _Mybase::ok:
if (_Mid2 == &_Ch + 1)
++_Wchars; // replacement do_in might not convert one
_First1 = _Mid1;
break;
default:
return ((int)_Wchars); // error or partial
}
}
return ((int)_Wchars);
}
virtual bool __CLR_OR_THIS_CALL do_always_noconv() const _THROW0()
{ // return true if conversions never change input
return (false);
}
virtual int __CLR_OR_THIS_CALL do_max_length() const _THROW0()
{ // return maximum length required for a conversion
return ((_Mode & _Consume_header) != 0 ? 9 // header + max input
: (_Mode & _Generate_header) != 0 ? 7 // header + max output
: 6); // 6-byte max input sequence, no 3-byte header
}
virtual int do_encoding() const _THROW0()
{ // return length of code sequence (from codecvt)
return (0); // 0 => varying length
}
private:
unsigned long _Maxcode; // default: 0x10ffff
_Codecvt_mode _Mode; // default: _Consume_header
};
// CLASS codecvt<char32_t, char, _Mbstatet>
template<>
class _CRTIMP2_PURE codecvt<char32_t, char, _Mbstatet>
: public codecvt_base
{ // facet for converting between char32_t and UTF-8 byte sequences
public:
typedef codecvt<char32_t, char, _Mbstatet> _Mybase;
typedef char32_t _Elem;
typedef char _Byte;
typedef _Mbstatet _Statype;
typedef _Elem intern_type;
typedef _Byte extern_type;
typedef _Statype state_type;
result __CLR_OR_THIS_CALL in(_Statype& _State,
const _Byte *_First1, const _Byte *_Last1, const _Byte *& _Mid1,
_Elem *_First2, _Elem *_Last2, _Elem *& _Mid2) const
{ // convert bytes [_First1, _Last1) to [_First2, _Last)
return (do_in(_State,
_First1, _Last1, _Mid1, _First2, _Last2, _Mid2));
}
result __CLR_OR_THIS_CALL out(_Statype& _State,
const _Elem *_First1, const _Elem *_Last1, const _Elem *& _Mid1,
_Byte *_First2, _Byte *_Last2, _Byte *& _Mid2) const
{ // convert [_First1, _Last1) to bytes [_First2, _Last)
return (do_out(_State,
_First1, _Last1, _Mid1, _First2, _Last2, _Mid2));
}
result __CLR_OR_THIS_CALL unshift(_Statype& _State,
_Byte *_First2, _Byte *_Last2, _Byte *& _Mid2) const
{ // generate bytes to return to default shift state
return (do_unshift(_State,
_First2, _Last2, _Mid2));
}
int __CLR_OR_THIS_CALL length(const _Statype& _State, const _Byte *_First1,
const _Byte *_Last1, size_t _Count) const
{ // return min(_Count, converted length of bytes [_First1, _Last1))
return (do_length(_State, _First1, _Last1, _Count));
}
__PURE_APPDOMAIN_GLOBAL static locale::id id;
explicit __CLR_OR_THIS_CALL codecvt(size_t _Refs = 0)
: codecvt_base(_Refs), _Maxcode(0xffffffff), _Mode(_Consume_header)
{ // construct from current locale
_BEGIN_LOCINFO(_Lobj)
_Init(_Lobj);
_END_LOCINFO()
}
__CLR_OR_THIS_CALL codecvt(const _Locinfo& _Lobj, size_t _Refs = 0)
: codecvt_base(_Refs), _Maxcode(0xffffffff), _Mode(_Consume_header)
{ // construct from specified locale
_Init(_Lobj);
}
__CLR_OR_THIS_CALL codecvt(const _Locinfo& _Lobj, unsigned long _Maxcode_arg,
_Codecvt_mode _Mode_arg, size_t _Refs = 0)
: codecvt_base(_Refs), _Maxcode(_Maxcode_arg), _Mode(_Mode_arg)
{ // construct from specified locale and parameters
_Init(_Lobj);
}
static size_t __CLRCALL_OR_CDECL _Getcat(const locale::facet **_Ppf = 0,
const locale *_Ploc = 0)
{ // return locale category mask and construct standard facet
if (_Ppf != 0 && *_Ppf == 0)
*_Ppf = _NEW_CRT codecvt<_Elem, _Byte, _Statype>(
_Locinfo(_Ploc->c_str()));
return (_X_CTYPE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -