📄 _num_put.c
字号:
/* * Copyright (c) 1999 * Silicon Graphics Computer Systems, Inc. * * Copyright (c) 1999 * Boris Fomitchev * * This material is provided "as is", with absolutely no warranty expressed * or implied. Any use is at your own risk. * * Permission to use or copy this software for any purpose is hereby granted * without fee, provided the above notices are retained on all copies. * Permission to modify the code and to distribute modified code is granted, * provided the above notices are retained, and a notice that the code was * modified is included with the above copyright notice. * */#ifndef _STLP_NUM_PUT_C#define _STLP_NUM_PUT_C#ifndef _STLP_INTERNAL_NUM_PUT_H# include <stl/_num_put.h>#endif#ifndef _STLP_INTERNAL_LIMITS# include <stl/_limits.h>#endif_STLP_BEGIN_NAMESPACE_STLP_MOVE_TO_PRIV_NAMESPACE// __do_put_float and its helper functions. Strategy: write the output// to a buffer of char, transform the buffer to _CharT, and then copy// it to the output.//----------------------------------------------------------------------// num_put facettemplate <class _CharT, class _OutputIter>_OutputIter _STLP_CALL__copy_float_and_fill(const _CharT* __first, const _CharT* __last, _OutputIter __oi, ios_base::fmtflags __flags, streamsize __width, _CharT __fill, _CharT __xplus, _CharT __xminus) { if (__width <= __last - __first) return copy(__first, __last, __oi); else { streamsize __pad = __width - (__last - __first); ios_base::fmtflags __dir = __flags & ios_base::adjustfield; if (__dir == ios_base::left) { __oi = copy(__first, __last, __oi); return __fill_n(__oi, __pad, __fill); } else if (__dir == ios_base::internal && __first != __last && (*__first == __xplus || *__first == __xminus)) { *__oi++ = *__first++; __oi = __fill_n(__oi, __pad, __fill); return copy(__first, __last, __oi); } else { __oi = __fill_n(__oi, __pad, __fill); return copy(__first, __last, __oi); } }}#if !defined (_STLP_NO_WCHAR_T)// Helper routine for wchar_ttemplate <class _OutputIter>_OutputIter _STLP_CALL__put_float(__iostring &__str, _OutputIter __oi, ios_base& __f, wchar_t __fill, wchar_t __decimal_point, wchar_t __sep, size_t __group_pos, const string& __grouping) { const ctype<wchar_t>& __ct = *__STATIC_CAST(const ctype<wchar_t>*, __f._M_ctype_facet()); __iowstring __wbuf; __convert_float_buffer(__str, __wbuf, __ct, __decimal_point); if (!__grouping.empty()) { __insert_grouping(__wbuf, __group_pos, __grouping, __sep, __ct.widen('+'), __ct.widen('-'), 0); } return __copy_float_and_fill(__CONST_CAST(wchar_t*, __wbuf.data()), __CONST_CAST(wchar_t*, __wbuf.data()) + __wbuf.size(), __oi, __f.flags(), __f.width(0), __fill, __ct.widen('+'), __ct.widen('-'));}#endif /* WCHAR_T */// Helper routine for chartemplate <class _OutputIter>_OutputIter _STLP_CALL__put_float(__iostring &__str, _OutputIter __oi, ios_base& __f, char __fill, char __decimal_point, char __sep, size_t __group_pos, const string& __grouping) { if ((__group_pos < __str.size()) && (__str[__group_pos] == '.')) { __str[__group_pos] = __decimal_point; } if (!__grouping.empty()) { __insert_grouping(__str, __group_pos, __grouping, __sep, '+', '-', 0); } return __copy_float_and_fill(__CONST_CAST(char*, __str.data()), __CONST_CAST(char*, __str.data()) + __str.size(), __oi, __f.flags(), __f.width(0), __fill, '+', '-');}template <class _CharT, class _OutputIter, class _Float>_OutputIter _STLP_CALL__do_put_float(_OutputIter __s, ios_base& __f, _CharT __fill, _Float __x) { __iostring __buf; size_t __group_pos = __write_float(__buf, __f.flags(), (int)__f.precision(), __x); const numpunct<_CharT>& __np = *__STATIC_CAST(const numpunct<_CharT>*, __f._M_numpunct_facet()); return __put_float(__buf, __s, __f, __fill, __np.decimal_point(), __np.thousands_sep(), __group_pos, __f._M_grouping());}inline void __get_money_digits_aux (__iostring &__buf, ios_base &, _STLP_LONGEST_FLOAT_TYPE __x){ __get_floor_digits(__buf, __x); }#if !defined (_STLP_NO_WCHAR_T)inline void __get_money_digits_aux (__iowstring &__wbuf, ios_base &__f, _STLP_LONGEST_FLOAT_TYPE __x) { __iostring __buf; __get_floor_digits(__buf, __x); const ctype<wchar_t>& __ct = *__STATIC_CAST(const ctype<wchar_t>*, __f._M_ctype_facet()); __convert_float_buffer(__buf, __wbuf, __ct, wchar_t(0), false);}#endiftemplate <class _CharT>void _STLP_CALL __get_money_digits(_STLP_BASIC_IOSTRING(_CharT) &__buf, ios_base& __f, _STLP_LONGEST_FLOAT_TYPE __x){ __get_money_digits_aux(__buf, __f, __x); }// _M_do_put_integer and its helper functions.template <class _CharT, class _OutputIter>_OutputIter _STLP_CALL__copy_integer_and_fill(const _CharT* __buf, ptrdiff_t __len, _OutputIter __oi, ios_base::fmtflags __flg, streamsize __wid, _CharT __fill, _CharT __xplus, _CharT __xminus) { if (__len >= __wid) return copy(__buf, __buf + __len, __oi); else { //casting numeric_limits<ptrdiff_t>::max to streamsize only works is ptrdiff_t is signed or streamsize representation //is larger than ptrdiff_t one. _STLP_STATIC_ASSERT((sizeof(streamsize) > sizeof(ptrdiff_t)) || (sizeof(streamsize) == sizeof(ptrdiff_t)) && numeric_limits<ptrdiff_t>::is_signed) ptrdiff_t __pad = __STATIC_CAST(ptrdiff_t, (min) (__STATIC_CAST(streamsize, (numeric_limits<ptrdiff_t>::max)()), __STATIC_CAST(streamsize, __wid - __len))); ios_base::fmtflags __dir = __flg & ios_base::adjustfield; if (__dir == ios_base::left) { __oi = copy(__buf, __buf + __len, __oi); return __fill_n(__oi, __pad, __fill); } else if (__dir == ios_base::internal && __len != 0 && (__buf[0] == __xplus || __buf[0] == __xminus)) { *__oi++ = __buf[0]; __oi = __fill_n(__oi, __pad, __fill); return copy(__buf + 1, __buf + __len, __oi); } else if (__dir == ios_base::internal && __len >= 2 && (__flg & ios_base::showbase) && (__flg & ios_base::basefield) == ios_base::hex) { *__oi++ = __buf[0]; *__oi++ = __buf[1]; __oi = __fill_n(__oi, __pad, __fill); return copy(__buf + 2, __buf + __len, __oi); } else { __oi = __fill_n(__oi, __pad, __fill); return copy(__buf, __buf + __len, __oi); } }}#if !defined (_STLP_NO_WCHAR_T)// Helper function for wchar_ttemplate <class _OutputIter>_OutputIter _STLP_CALL__put_integer(char* __buf, char* __iend, _OutputIter __s, ios_base& __f, ios_base::fmtflags __flags, wchar_t __fill) { locale __loc = __f.getloc(); // const ctype<wchar_t>& __ct = use_facet<ctype<wchar_t> >(__loc); const ctype<wchar_t>& __ct = *__STATIC_CAST(const ctype<wchar_t>*, __f._M_ctype_facet()); wchar_t __xplus = __ct.widen('+'); wchar_t __xminus = __ct.widen('-'); wchar_t __wbuf[64]; __ct.widen(__buf, __iend, __wbuf); ptrdiff_t __len = __iend - __buf; wchar_t* __eend = __wbuf + __len; // const numpunct<wchar_t>& __np = use_facet<numpunct<wchar_t> >(__loc); // const string& __grouping = __np.grouping(); const numpunct<wchar_t>& __np = *__STATIC_CAST(const numpunct<wchar_t>*, __f._M_numpunct_facet()); const string& __grouping = __f._M_grouping(); if (!__grouping.empty()) { int __basechars; if (__flags & ios_base::showbase) switch (__flags & ios_base::basefield) { case ios_base::hex: __basechars = 2; break; case ios_base::oct: __basechars = 1; break; default: __basechars = 0; } else __basechars = 0; __len = __insert_grouping(__wbuf, __eend, __grouping, __np.thousands_sep(), __xplus, __xminus, __basechars); } return __copy_integer_and_fill((wchar_t*)__wbuf, __len, __s, __flags, __f.width(0), __fill, __xplus, __xminus);}#endif// Helper function for chartemplate <class _OutputIter>_OutputIter _STLP_CALL__put_integer(char* __buf, char* __iend, _OutputIter __s, ios_base& __f, ios_base::fmtflags __flags, char __fill) { char __grpbuf[64]; ptrdiff_t __len = __iend - __buf; // const numpunct<char>& __np = use_facet<numpunct<char> >(__f.getloc()); // const string& __grouping = __np.grouping(); const numpunct<char>& __np = *__STATIC_CAST(const numpunct<char>*, __f._M_numpunct_facet()); const string& __grouping = __f._M_grouping(); if (!__grouping.empty()) { int __basechars; if (__flags & ios_base::showbase) switch (__flags & ios_base::basefield) { case ios_base::hex: __basechars = 2; break; case ios_base::oct: __basechars = 1; break; default: __basechars = 0; } else __basechars = 0; // make sure there is room at the end of the buffer // we pass to __insert_grouping copy(__buf, __iend, (char *) __grpbuf); __buf = __grpbuf; __iend = __grpbuf + __len; __len = __insert_grouping(__buf, __iend, __grouping, __np.thousands_sep(), '+', '-', __basechars); } return __copy_integer_and_fill(__buf, __len, __s, __flags, __f.width(0), __fill, '+', '-');}#if defined (_STLP_LONG_LONG)typedef _STLP_LONG_LONG __max_int_t;typedef unsigned _STLP_LONG_LONG __umax_int_t;#elsetypedef long __max_int_t;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -