📄 xloctime
字号:
template<class _OutIt>
class _CRTIMP2_PURE time_put<wchar_t, _OutIt>
: public locale::facet
{ // facet for converting encoded times to wchar_t text
public:
typedef wchar_t _Elem;
typedef _Elem char_type;
typedef _OutIt iter_type;
_OutIt __CLR_OR_THIS_CALL put(_OutIt _Dest,
ios_base& _Iosbase, _Elem _Fill, const tm *_Pt,
const _Elem *_Fmtfirst, const _Elem *_Fmtlast) const
{ // put formatted time from _Pt to _Dest for [_Fmtfirst, _Fmtlast)
_DEBUG_POINTER(_Dest);
_DEBUG_POINTER(_Pt);
const _Elem _Percent = _MAKLOCCHR(_Elem, '%', _Cvt);
for (; _Fmtfirst != _Fmtlast; ++_Fmtfirst)
if (*_Fmtfirst != _Percent)
*_Dest++ = *_Fmtfirst; // copy literal element
else if (++_Fmtfirst == _Fmtlast)
{ // treat trailing % as %%
*_Dest++ = _Percent;
break;
}
else
{ // get specifier after %
char _Specifier = _MAKLOCBYTE(_Elem, *_Fmtfirst, _Cvt);
char _Qualifier = '\0';
if (_Specifier != 'E' && _Specifier != 'O'
&& _Specifier != 'Q' && _Specifier != '#')
; // not [E0Q#] qualifier, treat as specifier
else if (++_Fmtfirst == _Fmtlast)
{ // no specifier, copy %[E0Q#] as literal elements
*_Dest++ = _Percent, *_Dest++ = _Specifier;
break;
}
else
{ // save both qualifier and specifier
_Qualifier = _Specifier;
_Specifier = _MAKLOCBYTE(_Elem, *_Fmtfirst, _Cvt);
}
_Dest = do_put(_Dest, _Iosbase, _Fill, _Pt,
_Specifier, _Qualifier); // convert a single field
}
return (_Dest);
}
_OutIt __CLR_OR_THIS_CALL put(_OutIt _Dest,
ios_base& _Iosbase, _Elem _Fill, const tm *_Pt,
char _Specifier, char _Modifier = 0) const
{ // put formatted time from _Pt to _Dest for _Specifier/_Modifier
return (do_put(_Dest, _Iosbase, _Fill, _Pt, _Specifier, _Modifier));
}
__PURE_APPDOMAIN_GLOBAL static locale::id id; // unique facet id
explicit __CLR_OR_THIS_CALL time_put(size_t _Refs = 0)
: locale::facet(_Refs)
{ // construct from current locale
_BEGIN_LOCINFO(_Lobj)
_Init(_Lobj);
_END_LOCINFO()
}
__CLR_OR_THIS_CALL time_put(const _Locinfo& _Lobj, size_t _Refs = 0)
: locale::facet(_Refs)
{ // construct from specified locale
_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 time_put<_Elem, _OutIt>(
_Locinfo(_Ploc->c_str()));
return (_X_TIME);
}
protected:
virtual __CLR_OR_THIS_CALL ~time_put()
{ // destroy the object
}
__CLR_OR_THIS_CALL time_put(const char *_Locname, size_t _Refs = 0)
: locale::facet(_Refs)
{ // construct from specified locale
_BEGIN_LOCINFO(_Lobj(_Locname))
_Init(_Lobj);
_END_LOCINFO()
}
void __CLR_OR_THIS_CALL _Init(const _Locinfo& _Lobj)
{ // initialize from _Lobj
_Cvt = _Lobj._Getcvt();
_Tnames = _Lobj._Gettnames();
}
virtual _OutIt __CLR_OR_THIS_CALL do_put(_OutIt _Dest,
ios_base&, _Elem, const tm *_Pt,
char _Specifier, char _Modifier = 0) const
{ // put formatted time from _Pt to _Dest for [_Fmtfirst, _Fmtlast)
_DEBUG_POINTER(_Dest);
_DEBUG_POINTER(_Pt);
char _Fmt[5] = "!%x\0"; // '!' for nonzero count, null for modifier
size_t _Count, _Num;
string _Str;
if (_Modifier == (_Elem)0)
_Fmt[2] = _Specifier;
else
_Fmt[2] = _Modifier, _Fmt[3] = _Specifier;
for (_Num = 16; ; _Num *= 2)
{ // convert into ever larger string buffer until success
_Str.append(_Num, '\0');
if (0 < (_Count = _Strftime(&*_Str.begin(), _Str.size(),
_Fmt, _Pt, _Tnames._Getptr())))
break;
}
int _Bytes;
_Mbstinit(_Mbst);
wchar_t _Wc;
--_Count; // skip '!'
for (string::const_iterator _Snext = _Str.begin() + 1; 0 < _Count;
_Count -= _Bytes, _Snext += _Bytes, *_Dest++ = _Wc)
switch (_Bytes = _Mbrtowc(&_Wc, &*_Snext, _Count, &_Mbst, &_Cvt))
{ // convert a wchar_t
case -2: // partial conversion
case -1: // failed conversion
return (_Dest);
case 0: // may have converted null character
if (_Wc == L'\0')
_Bytes = (int)_CSTD strlen(&*_Snext) + 1;
break;
case -3:
_Bytes = 0; // wchar_t generated from state info
}
return (_Dest);
}
private:
_Locinfo::_Timevec _Tnames; // locale-specific stuff for _Strftime
_Locinfo::_Cvtvec _Cvt; // conversion information
};
// STATIC time_put::id OBJECT
template<class _OutIt>
__PURE_APPDOMAIN_GLOBAL locale::id time_put<wchar_t, _OutIt>::id;
#ifdef _CRTBLD_NATIVE_WCHAR_T
// CLASS time_put<unsigned short>
template<class _OutIt>
class _CRTIMP2_PURE time_put<unsigned short, _OutIt>
: public locale::facet
{ // facet for converting encoded times to unsigned short text
public:
typedef unsigned short _Elem;
typedef _Elem char_type;
typedef _OutIt iter_type;
_OutIt __CLR_OR_THIS_CALL put(_OutIt _Dest,
ios_base& _Iosbase, _Elem _Fill, const tm *_Pt,
const _Elem *_Fmtfirst, const _Elem *_Fmtlast) const
{ // put formatted time from _Pt to _Dest for [_Fmtfirst, _Fmtlast)
_DEBUG_POINTER(_Dest);
_DEBUG_POINTER(_Pt);
const _Elem _Percent = _MAKLOCCHR(_Elem, '%', _Cvt);
for (; _Fmtfirst != _Fmtlast; ++_Fmtfirst)
if (*_Fmtfirst != _Percent)
*_Dest++ = *_Fmtfirst; // copy literal element
else if (++_Fmtfirst == _Fmtlast)
{ // treat trailing % as %%
*_Dest++ = _Percent;
break;
}
else
{ // get specifier after %
char _Specifier = _MAKLOCBYTE(_Elem, *_Fmtfirst, _Cvt);
char _Qualifier = '\0';
if (_Specifier != 'E' && _Specifier != 'O'
&& _Specifier != 'Q' && _Specifier != '#')
; // not [E0Q#] qualifier, treat as specifier
else if (++_Fmtfirst == _Fmtlast)
{ // no specifier, copy %[E0Q#] as literal elements
*_Dest++ = _Percent, *_Dest++ = _Specifier;
break;
}
else
{ // save both qualifier and specifier
_Qualifier = _Specifier;
_Specifier = _MAKLOCBYTE(_Elem, *_Fmtfirst, _Cvt);
}
_Dest = do_put(_Dest, _Iosbase, _Fill, _Pt,
_Specifier, _Qualifier); // convert a single field
}
return (_Dest);
}
_OutIt __CLR_OR_THIS_CALL put(_OutIt _Dest,
ios_base& _Iosbase, _Elem _Fill, const tm *_Pt,
char _Specifier, char _Modifier = 0) const
{ // put formatted time from _Pt to _Dest for _Specifier/_Modifier
return (do_put(_Dest, _Iosbase, _Fill, _Pt, _Specifier, _Modifier));
}
__PURE_APPDOMAIN_GLOBAL static locale::id id; // unique facet id
explicit __CLR_OR_THIS_CALL time_put(size_t _Refs = 0)
: locale::facet(_Refs)
{ // construct from current locale
_BEGIN_LOCINFO(_Lobj)
_Init(_Lobj);
_END_LOCINFO()
}
__CLR_OR_THIS_CALL time_put(const _Locinfo& _Lobj, size_t _Refs = 0)
: locale::facet(_Refs)
{ // construct from specified locale
_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 time_put<_Elem, _OutIt>(
_Locinfo(_Ploc->c_str()));
return (_X_TIME);
}
protected:
virtual __CLR_OR_THIS_CALL ~time_put()
{ // destroy the object
}
__CLR_OR_THIS_CALL time_put(const char *_Locname, size_t _Refs = 0)
: locale::facet(_Refs)
{ // construct from specified locale
_BEGIN_LOCINFO(_Lobj(_Locname))
_Init(_Lobj);
_END_LOCINFO()
}
void __CLR_OR_THIS_CALL _Init(const _Locinfo& _Lobj)
{ // initialize from _Lobj
_Cvt = _Lobj._Getcvt();
_Tnames = _Lobj._Gettnames();
}
virtual _OutIt __CLR_OR_THIS_CALL do_put(_OutIt _Dest,
ios_base&, _Elem, const tm *_Pt,
char _Specifier, char _Modifier = 0) const
{ // put formatted time from _Pt to _Dest for [_Fmtfirst, _Fmtlast)
_DEBUG_POINTER(_Dest);
_DEBUG_POINTER(_Pt);
char _Fmt[5] = "!%x\0"; // '!' for nonzero count, null for modifier
size_t _Count, _Num;
string _Str;
if (_Modifier == (_Elem)0)
_Fmt[2] = _Specifier;
else
_Fmt[2] = _Modifier, _Fmt[3] = _Specifier;
for (_Num = 16; ; _Num *= 2)
{ // convert into ever larger string buffer until success
_Str.append(_Num, '\0');
if (0 < (_Count = _Strftime(&*_Str.begin(), _Str.size(),
_Fmt, _Pt, _Tnames._Getptr())))
break;
}
int _Bytes;
_Mbstinit(_Mbst);
wchar_t _Wc;
--_Count; // skip '!'
for (string::const_iterator _Snext = _Str.begin() + 1; 0 < _Count;
_Count -= _Bytes, _Snext += _Bytes, *_Dest++ = _Wc)
switch (_Bytes = _Mbrtowc(&_Wc, &*_Snext, _Count, &_Mbst, &_Cvt))
{ // convert a wchar_t
case -2: // partial conversion
case -1: // failed conversion
return (_Dest);
case 0: // may have converted null character
if (_Wc == L'\0')
_Bytes = (int)_CSTD strlen(&*_Snext) + 1;
break;
case -3:
_Bytes = 0; // wchar_t generated from state info
}
return (_Dest);
}
private:
_Locinfo::_Timevec _Tnames; // locale-specific stuff for _Strftime
_Locinfo::_Cvtvec _Cvt; // conversion information
};
// STATIC time_put::id OBJECT
template<class _OutIt>
__PURE_APPDOMAIN_GLOBAL locale::id time_put<unsigned short, _OutIt>::id;
#endif /* _CRTBLD_NATIVE_WCHAR_T */
// TEMPLATE CLASS time_put_byname
template<class _Elem,
class _OutIt = ostreambuf_iterator<_Elem, char_traits<_Elem> > >
class time_put_byname
: public time_put<_Elem, _OutIt>
{ // time_put for named locale
public:
explicit time_put_byname(const char *_Locname, size_t _Refs = 0)
: time_put<_Elem, _OutIt>(_Locname, _Refs)
{ // construct for named locale
}
#if _HAS_CPP0X
explicit time_put_byname(const string& _Str, size_t _Refs = 0)
: time_put<_Elem, _OutIt>(_Str.c_str(), _Refs)
{ // construct for named locale
}
#endif /* _HAS_CPP0X */
protected:
virtual __CLR_OR_THIS_CALL ~time_put_byname()
{ // destroy the object
}
};
#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE)
#ifdef __FORCE_INSTANCE
template class _CRTIMP2_PURE time_get<char,
istreambuf_iterator<char, char_traits<char> > >;
template class _CRTIMP2_PURE time_put<char,
ostreambuf_iterator<char, char_traits<char> > >;
template class _CRTIMP2_PURE time_get<wchar_t,
istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
template class _CRTIMP2_PURE time_put<wchar_t,
ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
#ifdef _CRTBLD_NATIVE_WCHAR_T
template class _CRTIMP2_PURE time_get<unsigned short,
istreambuf_iterator<unsigned short, char_traits<unsigned short> > >;
template class _CRTIMP2_PURE time_put<unsigned short,
ostreambuf_iterator<unsigned short, char_traits<unsigned short> > >;
#endif /* _CRTBLD_NATIVE_WCHAR_T */
#endif /* __FORCE_INSTANCE */
#endif /* defined(_DLL_CPPLIB) etc. */
_STD_END
#pragma pop_macro("new")
#pragma warning(pop)
#pragma pack(pop)
#endif /* RC_INVOKED */
#endif /* _XLOCTIME_ */
/*
* Copyright (c) 1992-2009 by P.J. Plauger. ALL RIGHTS RESERVED.
* Consult your license regarding permissions and restrictions.
V5.20:0009 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -