📄 xlocnum
字号:
? 6 : _Iosbase.precision(); // desired precision
int _Significance = _MAX_SIG_DIG < _Precision
? _MAX_SIG_DIG : (int)_Precision; // actual sprintf precision
_Precision -= _Significance;
size_t _Beforepoint = 0; // zeros to add before decimal point
size_t _Afterpoint = 0; // zeros to add after decimal point
if ((_Iosbase.flags() & ios_base::floatfield) == ios_base::fixed
&& _Val * 0.5 != _Val) // skip -Inf, 0, Inf
{ // scale silly fixed-point value
bool _Signed = _Val < 0;
if (_Signed)
_Val = -_Val;
for (; 1e35 <= _Val && _Beforepoint < 5000; _Beforepoint += 10)
_Val /= 1e10; // drop 10 zeros before decimal point
if (0 < _Val)
for (; 10 <= _Precision && _Val <= 1e-35
&& _Afterpoint < 5000; _Afterpoint += 10)
{ // drop 10 zeros after decimal point
_Val *= 1e10;
_Precision -= 10;
}
if (_Signed)
_Val = -_Val;
}
return (_Fput(_Dest, _Iosbase, _Fill, _Buf,
_Beforepoint, _Afterpoint, (size_t)_Precision,
_CSTD sprintf_s(_Buf, sizeof (_Buf),
_Ffmt(_Fmt, 0, _Iosbase.flags()),
_Significance, _Val))); // convert and put
}
virtual _OutIt __CLR_OR_THIS_CALL do_put(_OutIt _Dest,
ios_base& _Iosbase, _Elem _Fill, long double _Val) const
{ // put formatted long double to _Dest
char _Buf[_MAX_EXP_DIG + _MAX_SIG_DIG + 64], _Fmt[8];
streamsize _Precision = _Iosbase.precision() <= 0
&& !(_Iosbase.flags() & ios_base::fixed)
? 6 : _Iosbase.precision(); // desired precision
int _Significance = _MAX_SIG_DIG < _Precision
? _MAX_SIG_DIG : (int)_Precision; // actual sprintf precision
_Precision -= _Significance;
size_t _Beforepoint = 0; // zeros to add before decimal point
size_t _Afterpoint = 0; // zeros to add after decimal point
if ((_Iosbase.flags() & ios_base::floatfield) == ios_base::fixed)
{ // scale silly fixed-point value
bool _Signed = _Val < 0;
if (_Signed)
_Val = -_Val;
for (; 1e35 <= _Val && _Beforepoint < 5000; _Beforepoint += 10)
_Val /= 1e10; // drop 10 zeros before decimal point
if (0 < _Val)
for (; 10 <= _Precision && _Val <= 1e-35
&& _Afterpoint < 5000; _Afterpoint += 10)
{ // drop 10 zeros after decimal point
_Val *= 1e10;
_Precision -= 10;
}
if (_Signed)
_Val = -_Val;
}
return (_Fput(_Dest, _Iosbase, _Fill, _Buf,
_Beforepoint, _Afterpoint, (size_t)_Precision,
_CSTD sprintf_s(_Buf, sizeof (_Buf),
_Ffmt(_Fmt, 'L', _Iosbase.flags()),
_Significance, _Val))); // convert and put
}
virtual _OutIt __CLR_OR_THIS_CALL do_put(_OutIt _Dest,
ios_base& _Iosbase, _Elem _Fill, const void *_Val) const
{ // put formatted void pointer to _Dest
char _Buf[2 * _MAX_INT_DIG];
return (_Iput(_Dest, _Iosbase, _Fill, _Buf,
_CSTD sprintf_s(_Buf, sizeof (_Buf), "%p", _Val)));
}
private:
char *__CLRCALL_OR_CDECL _Ffmt(char *_Fmt,
char _Spec, ios_base::fmtflags _Flags) const
{ // generate sprintf format for floating-point
char *_Ptr = _Fmt;
*_Ptr++ = '%';
if (_Flags & ios_base::showpos)
*_Ptr++ = '+';
if (_Flags & ios_base::showpoint)
*_Ptr++ = '#';
*_Ptr++ = '.';
*_Ptr++ = '*'; // for precision argument
if (_Spec != '\0')
*_Ptr++ = _Spec; // 'L' qualifier for long double only
ios_base::fmtflags _Ffl = _Flags & ios_base::floatfield;
*_Ptr++ = _Ffl == ios_base::fixed ? 'f'
: _Ffl == ios_base::hexfloat ? 'a' // added with TR1
: _Ffl == ios_base::scientific ? 'e' : 'g'; // specifier
*_Ptr = '\0';
return (_Fmt);
}
_OutIt __CLRCALL_OR_CDECL _Fput(_OutIt _Dest,
ios_base& _Iosbase, _Elem _Fill, const char *_Buf,
size_t _Beforepoint, size_t _Afterpoint,
size_t _Trailing, size_t _Count) const
{ // put formatted floating-point to _Dest
_DEBUG_POINTER(_Dest);
const _Mypunct& _Punct_fac = _USE(_Iosbase.getloc(), _Mypunct);
const string _Grouping = _Punct_fac.grouping();
const _Elem _Kseparator = _Punct_fac.thousands_sep();
string _Groupstring;
const _Elem _E0 = _MAKLOCCHR(_Elem, '0', _Cvt);
size_t _Prefix = _Buf[0] == '+' || _Buf[0] == '-' ? 1 : 0;
char _Enders[3];
_Enders[0] = _CSTD localeconv()->decimal_point[0];
_Enders[1] = 'e';
_Enders[2] = '\0';
const char *_Eptr = (const char *)_CSTD memchr(_Buf,
'e', _Count); // find exponent
const char *_Pointptr = (const char *)_CSTD memchr(_Buf,
_Enders[0], _Count); // find decimal point
if (_Pointptr == 0)
_Trailing = 0;
if (*_Grouping.c_str() != CHAR_MAX && '\0' < *_Grouping.c_str())
{ // grouping specified, add thousands separators
_Groupstring.append(_Buf, _Count); // assemble field into string
if (_Eptr == 0)
_Groupstring.append(_Trailing, '0');
else
{ /* dispose of any zeros before exponent */
if (_Pointptr == 0)
{ /* no point but exponent, put scaling zeros */
_Groupstring.append(_Beforepoint, '0');
_Beforepoint = 0;
}
_Groupstring.insert(_Eptr - _Buf, _Trailing, '0');
}
_Trailing = 0;
if (_Pointptr == 0)
_Groupstring.append(_Beforepoint, '0');
else
{ // fill in zeros around decimal point
_Groupstring.insert(_Pointptr - _Buf + 1, _Afterpoint, '0');
_Groupstring.insert(_Pointptr - _Buf, _Beforepoint, '0');
_Afterpoint = 0;
}
_Beforepoint = 0;
const char *_Pg = _Grouping.c_str();
size_t _Off = _CSTD strcspn(&_Groupstring[0], &_Enders[0]);
while (*_Pg != CHAR_MAX && '\0' < *_Pg
&& (size_t)*_Pg < _Off - _Prefix)
{ // add a NUL to mark thousands separator
_Groupstring.insert(_Off -= *_Pg, (size_t)1, '\0');
if ('\0' < _Pg[1])
++_Pg; // not last group, advance
}
_Buf = &_Groupstring[0];
_Trailing = 0;
_Count = _Groupstring.size();
}
size_t _Fillcount = _Beforepoint + _Afterpoint + _Trailing + _Count;
_Fillcount = _Iosbase.width() <= 0
|| (size_t)_Iosbase.width() <= _Fillcount
? 0 : (size_t)_Iosbase.width() - _Fillcount;
ios_base::fmtflags _Adjustfield =
_Iosbase.flags() & ios_base::adjustfield;
if (_Adjustfield != ios_base::left
&& _Adjustfield != ios_base::internal)
{ // put leading fill
_Dest = _Rep(_Dest, _Fill, _Fillcount);
_Fillcount = 0;
}
else if (_Adjustfield == ios_base::internal)
{ // put internal fill
if (0 < _Prefix)
{ // but first put sign
_Dest = _Putc(_Dest, _Buf, 1);
++_Buf, --_Count;
}
_Dest = _Rep(_Dest, _Fill, _Fillcount);
_Fillcount = 0;
}
_Pointptr = (const char *)_CSTD memchr(_Buf,
_Enders[0], _Count); // find decimal point again
if (_Pointptr != 0)
{ // has decimal point, put pieces and zero fills
size_t _Fracoffset = _Pointptr - _Buf + 1;
_Dest = _Putgrouped(_Dest, _Buf, _Fracoffset - 1, _Kseparator);
_Dest = _Rep(_Dest, _E0, _Beforepoint);
_Dest = _Rep(_Dest, _Punct_fac.decimal_point(), 1);
_Dest = _Rep(_Dest, _E0, _Afterpoint);
_Buf += _Fracoffset, _Count -= _Fracoffset;
}
_Eptr = (const char *)_CSTD memchr(_Buf,
'e', _Count); // find exponent again
if (_Eptr != 0)
{ // has exponent field, put it out
size_t _Expoffset = _Eptr - _Buf + 1;
_Dest = _Putgrouped(_Dest, _Buf, _Expoffset - 1, _Kseparator);
_Dest = _Rep(_Dest, _E0, _Trailing), _Trailing = 0;
_Dest = _Putc(_Dest, _Iosbase.flags() & ios_base::uppercase
? "E" : "e", 1);
_Buf += _Expoffset, _Count -= _Expoffset;
}
_Dest = _Putgrouped(_Dest, _Buf, _Count,
_Kseparator); // put leftover field
_Dest = _Rep(_Dest, _E0, _Trailing); // put trailing zeros
_Iosbase.width(0);
return (_Rep(_Dest, _Fill, _Fillcount)); // put trailing fill
}
char *__CLRCALL_OR_CDECL _Ifmt(char *_Fmt,
const char *_Spec, ios_base::fmtflags _Flags) const
{ // generate sprintf format for integer
char *_Ptr = _Fmt;
*_Ptr++ = '%';
if (_Flags & ios_base::showpos)
*_Ptr++ = '+';
if (_Flags & ios_base::showbase)
*_Ptr++ = '#';
if (_Spec[0] != 'L')
*_Ptr++ = _Spec[0]; // qualifier
else
{ /* change L to I64 */
*_Ptr++ = 'I';
*_Ptr++ = '6';
*_Ptr++ = '4';
}
ios_base::fmtflags _Basefield = _Flags & ios_base::basefield;
*_Ptr++ = _Basefield == ios_base::oct ? 'o'
: _Basefield != ios_base::hex ? _Spec[1] // 'd' or 'u'
: _Flags & ios_base::uppercase ? 'X' : 'x';
*_Ptr = '\0';
return (_Fmt);
}
_OutIt __CLRCALL_OR_CDECL _Iput(_OutIt _Dest,
ios_base& _Iosbase, _Elem _Fill, char *_Buf, size_t _Count) const
{ // put formatted integer to _Dest
_DEBUG_POINTER(_Dest);
const _Mypunct& _Punct_fac = _USE(_Iosbase.getloc(), _Mypunct);
const string _Grouping = _Punct_fac.grouping();
const size_t _Prefix = *_Buf == '+' || *_Buf == '-' ? 1
: *_Buf == '0' && (_Buf[1] == 'x' || _Buf[1] == 'X') ? 2
: 0;
if (*_Grouping.c_str() != CHAR_MAX && '\0' < *_Grouping.c_str())
{ // grouping specified, add thousands separators
const char *_Pg = _Grouping.c_str();
size_t _Off = _Count;
while (*_Pg != CHAR_MAX && '\0' < *_Pg
&& (size_t)*_Pg < _Off - _Prefix)
{ // add a NUL to mark thousands separator
_Off -= *_Pg;
__analysis_assume(_Count + 1 > _Off);
_CRT_SECURE_MEMMOVE(&_Buf[_Off + 1], _Count + 1 - _Off,
&_Buf[_Off], _Count + 1 - _Off);
_Buf[_Off] = '\0', ++_Count;
if ('\0' < _Pg[1])
++_Pg; // not last group, advance
}
}
size_t _Fillcount = _Iosbase.width() <= 0
|| (size_t)_Iosbase.width() <= _Count
? 0 : (size_t)_Iosbase.width() - _Count;
ios_base::fmtflags _Adjustfield =
_Iosbase.flags() & ios_base::adjustfield;
if (_Adjustfield != ios_base::left
&& _Adjustfield != ios_base::internal)
{ // put leading fill
_Dest = _Rep(_Dest, _Fill, _Fillcount);
_Fillcount = 0;
}
else if (_Adjustfield == ios_base::internal)
{ // put internal fill
_Dest = _Putc(_Dest, _Buf, _Prefix); // put prefix
_Buf += _Prefix, _Count -= _Prefix;
_Dest = _Rep(_Dest, _Fill, _Fillcount), _Fillcount = 0;
}
_Dest = _Putgrouped(_Dest, _Buf, _Count,
_Punct_fac.thousands_sep()); // put field
_Iosbase.width(0);
return (_Rep(_Dest, _Fill, _Fillcount)); // put trailing fill
}
_OutIt __CLRCALL_OR_CDECL _Put(_OutIt _Dest,
const _Elem *_Ptr, size_t _Count) const
{ // put [_Ptr, _Ptr + _Count) to _Dest
for (; 0 < _Count; --_Count, ++_Dest, ++_Ptr)
*_Dest = *_Ptr;
return (_Dest);
}
_OutIt __CLRCALL_OR_CDECL _Putc(_OutIt _Dest,
const char *_Ptr, size_t _Count) const
{ // put char sequence [_Ptr, _Ptr + _Count) to _Dest
for (; 0 < _Count; --_Count, ++_Dest, ++_Ptr)
*_Dest = _MAKLOCCHR(_Elem, *_Ptr, _Cvt);
return (_Dest);
}
_OutIt __CLRCALL_OR_CDECL _Putgrouped(_OutIt _Dest,
const char *_Ptr, size_t _Count, _Elem _Kseparator) const
{ // put char sequence [_Ptr, _Ptr + _Count) to _Dest with commas
for (; ; ++_Ptr, --_Count)
{ // put field with thousands separators for NULs
const char *_Pend =
(const char *)_CSTD memchr(_Ptr, '\0', _Count);
size_t _Groupsize = _Pend != 0 ? _Pend - _Ptr : _Count;
_Dest = _Putc(_Dest, _Ptr, _Groupsize);
_Ptr += _Groupsize, _Count -= _Groupsize;
if (_Count == 0)
break;
if (_Kseparator != (_Elem)0)
_Dest = _Rep(_Dest, _Kseparator, 1);
}
return (_Dest);
}
_OutIt __CLRCALL_OR_CDECL _Rep(_OutIt _Dest,
_Elem _Ch, size_t _Count) const
{ // put _Count * _Ch to _Dest
for (; 0 < _Count; --_Count, ++_Dest)
*_Dest = _Ch;
return (_Dest);
}
};
// STATIC num_put::id OBJECT
template<class _Elem,
class _OutIt>
__PURE_APPDOMAIN_GLOBAL locale::id num_put<_Elem, _OutIt>::id;
#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE)
#ifdef __FORCE_INSTANCE
template __PURE_APPDOMAIN_GLOBAL locale::id numpunct<char>::id;
template class _CRTIMP2_PURE num_get<char,
istreambuf_iterator<char, char_traits<char> > >;
template class _CRTIMP2_PURE num_put<char,
ostreambuf_iterator<char, char_traits<char> > >;
template __PURE_APPDOMAIN_GLOBAL locale::id numpunct<wchar_t>::id;
template class _CRTIMP2_PURE num_get<wchar_t,
istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
template class _CRTIMP2_PURE num_put<wchar_t,
ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
#ifdef _CRTBLD_NATIVE_WCHAR_T
template __PURE_APPDOMAIN_GLOBAL locale::id numpunct<unsigned short>::id;
template class _CRTIMP2_PURE num_get<unsigned short,
istreambuf_iterator<unsigned short, char_traits<unsigned short> > >;
template class _CRTIMP2_PURE num_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 /* _XLOCNUM_ */
/*
* 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 + -