📄 xlocale
字号:
{return (_LC_CTYPE); }
_PROTECTED:
virtual ~codecvt()
{};
protected:
void _Init(const _Locinfo& _Lobj)
{_Cvt = _Lobj._Getcvt(); }
virtual result do_in(_St& _State,
const _To *_F1, const _To *_L1, const _To *& _Mid1,
_E *_F2, _E *_L2, _E *& _Mid2) const
{_Mid1 = _F1, _Mid2 = _F2;
result _Ans = _Mid1 == _L1 ? ok : partial;
int _N;
while (_Mid1 != _L1 && _Mid2 != _L2)
switch (_N =
_Mbrtowc(_Mid2, _Mid1, _L1 - _Mid1,
&_State, &_Cvt))
{case -2:
_Mid1 = _L1;
return (_Ans);
case -1:
return (error);
case 0:
_N = strlen(_Mid1) + 1;
default: // fall through
_Mid1 += _N, ++_Mid2, _Ans = ok; }
return (_Ans); }
virtual result do_out(_St& _State,
const _E *_F1, const _E *_L1, const _E *& _Mid1,
_To *_F2, _To *_L2, _To *& _Mid2) const
{_Mid1 = _F1, _Mid2 = _F2;
result _Ans = _Mid1 == _L1 ? ok : partial;
int _N;
while (_Mid1 != _L1 && _Mid2 != _L2)
if (MB_CUR_MAX <= _L2 - _Mid2)
if ((_N =
_Wcrtomb(_Mid2, *_Mid1, &_State,
&_Cvt)) <= 0)
return (error);
else
++_Mid1, _Mid2 += _N, _Ans = ok;
else
{_To _Buf[MB_LEN_MAX];
_St _Stsave = _State;
if ((_N =
_Wcrtomb(_Buf, *_Mid1, &_State,
&_Cvt)) <= 0)
return (error);
else if (_L2 - _Mid2 < _N)
{_State = _Stsave;
return (_Ans); }
else
{memcpy(_Mid2, _Buf, _N);
++_Mid1, _Mid2 += _N, _Ans = ok; }}
return (_Ans); }
virtual int do_length(_St& _State, const _E *_F1,
const _E *_L1, size_t _N2) const _THROW0()
{const _E *_Mid1;
_To _Buf[MB_LEN_MAX];
int _N;
for (_Mid1 = _F1; _Mid1 != _L1 && 0 < _N2;
++_Mid1, _N2 -= _N)
if ((_N =
_Wcrtomb(_Buf, *_Mid1, &_State, &_Cvt)) <= 0
|| _N2 < _N)
break;
return (_Mid1 - _F1); }
virtual bool do_always_noconv() const _THROW0()
{return (false); }
virtual int do_max_length() const _THROW0()
{return (MB_LEN_MAX); }
virtual int do_encoding() const _THROW0()
{return (0); }
private:
_Locinfo::_Cvtvec _Cvt;
};
// TEMPLATE CLASS codecvt_byname
template<class _E, class _To, class _St>
class codecvt_byname : public codecvt<_E, _To, _St> {
public:
explicit codecvt_byname(const char *_S, size_t _R = 0)
: codecvt<_E, _To, _St>(_Locinfo(_S), _R) {}
_PROTECTED:
virtual ~codecvt_byname()
{}
};
// STRUCT ctype_base
struct _CRTIMP ctype_base : public locale::facet {
enum _Mask {alnum = _DI|_LO|_UP|_XA, alpha = _LO|_UP|_XA,
cntrl = _BB, digit = _DI, graph = _DI|_LO|_PU|_UP|_XA,
lower = _LO, print = _DI|_LO|_PU|_SP|_UP|_XA|_XD,
punct = _PU, space = _CN|_SP|_XS, upper = _UP,
xdigit = _XD};
// _BITMASK(_Mask, mask);
typedef short mask; // to match <ctype.h>
ctype_base(size_t _R = 0)
: locale::facet(_R) {}
};
// TEMPLATE CLASS ctype
template<class _E>
class ctype : public ctype_base {
public:
typedef _E char_type;
bool is(mask _M, _E _C) const
{return (do_is(_M, _C)); }
const _E *is(const _E *_F, const _E *_L, mask *_V) const
{return (do_is(_F, _L, _V)); }
const _E *scan_is(mask _M, const _E *_F,
const _E *_L) const
{return (do_scan_is(_M, _F, _L)); }
const _E *scan_not(mask _M, const _E *_F,
const _E *_L) const
{return (do_scan_not(_M, _F, _L)); }
_E tolower(_E _C) const
{return (do_tolower(_C)); }
const _E *tolower(_E *_F, const _E *_L) const
{return (do_tolower(_F, _L)); }
_E toupper(_E _C) const
{return (do_toupper(_C)); }
const _E *toupper(_E *_F, const _E *_L) const
{return (do_toupper(_F, _L)); }
_E widen(char _X) const
{return (do_widen(_X)); }
const char *widen(const char *_F, const char *_L,
_E *_V) const
{return (do_widen(_F, _L, _V)); }
char narrow(_E _C, char _D = '\0') const
{return (do_narrow(_C, _D)); }
const _E *narrow(const _E *_F, const _E *_L, char _D,
char *_V) const
{return (do_narrow(_F, _L, _D, _V)); }
static locale::id id;
explicit ctype(size_t _R = 0)
: ctype_base(_R) {_Init(_Locinfo()); }
ctype(const _Locinfo& _Lobj, size_t _R = 0)
: ctype_base(_R) {_Init(_Lobj); }
static size_t __cdecl _Getcat()
{return (_LC_CTYPE); }
_PROTECTED:
virtual ~ctype()
{if (_Ctype._Delfl)
free((void *)_Ctype._Table); }
protected:
void _Init(const _Locinfo& _Lobj)
{_Ctype = _Lobj._Getctype(); }
virtual bool do_is(mask _M, _E _C) const
{return ((_Ctype._Table[narrow(_C)] & _M) != 0); }
virtual const _E *do_is(const _E *_F, const _E *_L,
mask *_V) const
{for (; _F != _L; ++_F, ++_V)
*_V = _Ctype._Table[narrow(*_F)];
return (_F); }
virtual const _E *do_scan_is(mask _M, const _E *_F,
const _E *_L) const
{for (; _F != _L && !is(_M, *_F); ++_F)
;
return (_F); }
virtual const _E *do_scan_not(mask _M, const _E *_F,
const _E *_L) const
{for (; _F != _L && is(_M, *_F); ++_F)
;
return (_F); }
virtual _E do_tolower(_E _C) const
{return ((_E)widen((char)_Tolower(narrow(_C), &_Ctype))); }
virtual const _E *do_tolower(_E *_F, const _E *_L) const
{for (; _F != _L; ++_F)
*_F = (_E)_Tolower(*_F, &_Ctype);
return ((const _E *)_F); }
virtual _E do_toupper(_E _C) const
{return ((_E)widen((char)_Toupper(narrow(_C), &_Ctype))); }
virtual const _E *do_toupper(_E *_F, const _E *_L) const
{for (; _F != _L; ++_F)
*_F = (_E)_Toupper(*_F, &_Ctype);
return ((const _E *)_F); }
virtual _E do_widen(char _X) const
{return (_WIDEN(_E, _X)); }
virtual const char *do_widen(const char *_F, const char *_L,
_E *_V) const
{for (; _F != _L; ++_F, ++_V)
*_V = _WIDEN(_E, *_F);
return (_F); }
virtual char do_narrow(_E _C, char) const
{return ((char)_NARROW(_E, _C)); }
virtual const _E *do_narrow(const _E *_F, const _E *_L,
char, char *_V) const
{for (; _F != _L; ++_F, ++_V)
*_V = (char)_NARROW(_E, *_F);
return (_F); }
private:
_Locinfo::_Ctypevec _Ctype;
};
template<class _E>
locale::id ctype<_E>::id;
// CLASS ctype<char>
class _CRTIMP ctype<char> : public ctype_base {
public:
typedef char _E;
typedef _E char_type;
bool is(mask _M, _E _C) const
{return ((_Ctype._Table[(unsigned char)_C] & _M) != 0); }
const _E *is(const _E *_F, const _E *_L, mask *_V) const
{for (; _F != _L; ++_F, ++_V)
*_V = _Ctype._Table[(unsigned char)*_F];
return (_F); }
const _E *scan_is(mask _M, const _E *_F,
const _E *_L) const
{for (; _F != _L && !is(_M, *_F); ++_F)
;
return (_F); }
const _E *scan_not(mask _M, const _E *_F,
const _E *_L) const
{for (; _F != _L && is(_M, *_F); ++_F)
;
return (_F); }
_E tolower(_E _C) const
{return (do_tolower(_C)); }
const _E *tolower(_E *_F, const _E *_L) const
{return (do_tolower(_F, _L)); }
_E toupper(_E _C) const
{return (do_toupper(_C)); }
const _E *toupper(_E *_F, const _E *_L) const
{return (do_toupper(_F, _L)); }
_E widen(char _X) const
{return (_X); }
const _E *widen(const char *_F, const char *_L, _E *_V) const
{memcpy(_V, _F, _L - _F);
return (_L); }
_E narrow(_E _C, char _D = '\0') const
{return (_C); }
const _E *narrow(const _E *_F, const _E *_L, char _D,
char *_V) const
{memcpy(_V, _F, _L - _F);
return (_L); }
static locale::id id;
explicit ctype(const mask *_Tab = 0, bool _Df = false,
size_t _R = 0)
: ctype_base(_R)
{_Lockit Lk;
_Init(_Locinfo());
if (_Ctype._Delfl)
free((void *)_Ctype._Table), _Ctype._Delfl = false;
if (_Tab == 0)
_Ctype._Table = _Cltab;
else
_Ctype._Table = _Tab, _Ctype._Delfl = _Df; }
ctype(const _Locinfo& _Lobj, size_t _R = 0)
: ctype_base(_R) {_Init(_Lobj); }
static size_t __cdecl _Getcat()
{return (_LC_CTYPE); }
static const size_t table_size;
_PROTECTED:
virtual ~ctype()
{if (_Ctype._Delfl)
free((void *)_Ctype._Table); }
protected:
static void __cdecl _Term(void)
{free((void *)_Cltab); }
void _Init(const _Locinfo& _Lobj)
{_Lockit Lk;
_Ctype = _Lobj._Getctype();
if (_Cltab == 0)
{_Cltab = _Ctype._Table;
atexit(_Term);
_Ctype._Delfl = false; }}
virtual _E do_tolower(_E _C) const
{return (_E)(_Tolower((unsigned char)_C, &_Ctype)); }
virtual const _E *do_tolower(_E *_F, const _E *_L) const
{for (; _F != _L; ++_F)
*_F = (_E)_Tolower(*_F, &_Ctype);
return ((const _E *)_F); }
virtual _E do_toupper(_E _C) const
{return ((_E)_Toupper((unsigned char)_C, &_Ctype)); }
virtual const _E *do_toupper(_E *_F, const _E *_L) const
{for (; _F != _L; ++_F)
*_F = (_E)_Toupper(*_F, &_Ctype);
return ((const _E *)_F); }
const mask *table() const _THROW0()
{return (_Ctype._Table); }
static const mask * __cdecl classic_table() _THROW0()
{_Lockit Lk;
if (_Cltab == 0)
locale::classic(); // force locale::_Init() call
return (_Cltab); }
private:
_Locinfo::_Ctypevec _Ctype;
static const mask *_Cltab;
};
// TEMPLATE CLASS ctype_byname
template<class _E>
class ctype_byname : public ctype<_E> {
public:
explicit ctype_byname(const char *_S, size_t _R = 0)
: ctype<_E>(_Locinfo(_S), _R) {}
_PROTECTED:
virtual ~ctype_byname()
{}
};
#ifdef _DLL
#pragma warning(disable:4231) /* the extern before template is a non-standard extension */
extern template class _CRTIMP ctype<wchar_t>;
extern template class _CRTIMP codecvt<char, char, int>;
#pragma warning(default:4231) /* restore previous warning */
#endif // _DLL
_STD_END
#ifdef _MSC_VER
#pragma pack(pop)
#endif /* _MSC_VER */
#endif /* _XLOCALE_ */
/*
* Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
* Consult your license regarding permissions and restrictions.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -