⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 locale_facets.tcc

📁 linux下编程用 编译软件
💻 TCC
📖 第 1 页 / 共 5 页
字号:
    { return __int_to_char(__bufend, __v, __lit, __flags, false); }#ifdef _GLIBCXX_USE_LONG_LONG  template<typename _CharT>    inline int    __int_to_char(_CharT* __bufend, long long __v, const _CharT* __lit,		  ios_base::fmtflags __flags)    {      unsigned long long __ull = __v;      const ios_base::fmtflags __basefield = __flags & ios_base::basefield;      if (__builtin_expect(__basefield != ios_base::oct			   && __basefield != ios_base::hex, true))	__ull = __v < 0 ? -__v : __ull;      return __int_to_char(__bufend, __ull, __lit, __flags, false);    }  template<typename _CharT>    inline int    __int_to_char(_CharT* __bufend, unsigned long long __v, 		  const _CharT* __lit, ios_base::fmtflags __flags)    { return __int_to_char(__bufend, __v, __lit, __flags, false); }#endif  // N.B. The last argument is currently unused (see libstdc++/20914).  template<typename _CharT, typename _ValueT>    int    __int_to_char(_CharT* __bufend, _ValueT __v, const _CharT* __lit,		  ios_base::fmtflags __flags, bool)    {      const ios_base::fmtflags __basefield = __flags & ios_base::basefield;      _CharT* __buf = __bufend;      if (__builtin_expect(__basefield != ios_base::oct			   && __basefield != ios_base::hex, true))	{	  // Decimal.	  do	    {	      *--__buf = __lit[(__v % 10) + __num_base::_S_odigits];	      __v /= 10;	    }	  while (__v != 0);	}      else if (__basefield == ios_base::oct)	{	  // Octal.	  do	    {	      *--__buf = __lit[(__v & 0x7) + __num_base::_S_odigits];	      __v >>= 3;	    }	  while (__v != 0);	}      else	{	  // Hex.	  const bool __uppercase = __flags & ios_base::uppercase;	  const int __case_offset = __uppercase ? __num_base::_S_oudigits	                                        : __num_base::_S_odigits;	  do	    {	      *--__buf = __lit[(__v & 0xf) + __case_offset];	      __v >>= 4;	    }	  while (__v != 0);	}      return __bufend - __buf;    }  template<typename _CharT, typename _OutIter>    void    num_put<_CharT, _OutIter>::    _M_group_int(const char* __grouping, size_t __grouping_size, _CharT __sep,		 ios_base&, _CharT* __new, _CharT* __cs, int& __len) const    {      _CharT* __p = std::__add_grouping(__new, __sep, __grouping,					__grouping_size, __cs, __cs + __len);      __len = __p - __new;    }    template<typename _CharT, typename _OutIter>    template<typename _ValueT>      _OutIter      num_put<_CharT, _OutIter>::      _M_insert_int(_OutIter __s, ios_base& __io, _CharT __fill,		    _ValueT __v) const      {	typedef __numpunct_cache<_CharT>	        __cache_type;	__use_cache<__cache_type> __uc;	const locale& __loc = __io._M_getloc();	const __cache_type* __lc = __uc(__loc);	const _CharT* __lit = __lc->_M_atoms_out;	const ios_base::fmtflags __flags = __io.flags();	// Long enough to hold hex, dec, and octal representations.	const int __ilen = 5 * sizeof(_ValueT);	_CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)							     * __ilen));	// [22.2.2.2.2] Stage 1, numeric conversion to character.	// Result is returned right-justified in the buffer.	int __len = __int_to_char(__cs + __ilen, __v, __lit, __flags);	__cs += __ilen - __len;	// Add grouping, if necessary.	if (__lc->_M_use_grouping)	  {	    // Grouping can add (almost) as many separators as the number	    // of digits + space is reserved for numeric base or sign.	    _CharT* __cs2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)								  * (__len + 1)								  * 2));	    _M_group_int(__lc->_M_grouping, __lc->_M_grouping_size,			 __lc->_M_thousands_sep, __io, __cs2 + 2, __cs, __len);	    __cs = __cs2 + 2;	  }	// Complete Stage 1, prepend numeric base or sign.	const ios_base::fmtflags __basefield = __flags & ios_base::basefield;	if (__builtin_expect(__basefield != ios_base::oct			     && __basefield != ios_base::hex, true))	  {	    // Decimal.	    if (__v > 0)	      {		if (__flags & ios_base::showpos		    && numeric_limits<_ValueT>::is_signed)		  *--__cs = __lit[__num_base::_S_oplus], ++__len;	      }	    else if (__v)	      *--__cs = __lit[__num_base::_S_ominus], ++__len;	  }	else if (__flags & ios_base::showbase && __v)	  {	    if (__basefield == ios_base::oct)	      *--__cs = __lit[__num_base::_S_odigits], ++__len;	    else	      {		// 'x' or 'X'		const bool __uppercase = __flags & ios_base::uppercase;		*--__cs = __lit[__num_base::_S_ox + __uppercase];		// '0'		*--__cs = __lit[__num_base::_S_odigits];		__len += 2;	      }	  }	// Pad.	const streamsize __w = __io.width();	if (__w > static_cast<streamsize>(__len))	  {	    _CharT* __cs3 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)								  * __w));	    _M_pad(__fill, __w, __io, __cs3, __cs, __len);	    __cs = __cs3;	  }	__io.width(0);	// [22.2.2.2.2] Stage 4.	// Write resulting, fully-formatted string to output iterator.	return std::__write(__s, __cs, __len);      }  template<typename _CharT, typename _OutIter>    void    num_put<_CharT, _OutIter>::    _M_group_float(const char* __grouping, size_t __grouping_size,		   _CharT __sep, const _CharT* __p, _CharT* __new,		   _CharT* __cs, int& __len) const    {      // _GLIBCXX_RESOLVE_LIB_DEFECTS      // 282. What types does numpunct grouping refer to?      // Add grouping, if necessary.      const int __declen = __p ? __p - __cs : __len;      _CharT* __p2 = std::__add_grouping(__new, __sep, __grouping,					 __grouping_size,					 __cs, __cs + __declen);      // Tack on decimal part.      int __newlen = __p2 - __new;      if (__p)	{	  char_traits<_CharT>::copy(__p2, __p, __len - __declen);	  __newlen += __len - __declen;	}      __len = __newlen;    }  // The following code uses snprintf (or sprintf(), when  // _GLIBCXX_USE_C99 is not defined) to convert floating point values  // for insertion into a stream.  An optimization would be to replace  // them with code that works directly on a wide buffer and then use  // __pad to do the padding.  It would be good to replace them anyway  // to gain back the efficiency that C++ provides by knowing up front  // the type of the values to insert.  Also, sprintf is dangerous  // since may lead to accidental buffer overruns.  This  // implementation follows the C++ standard fairly directly as  // outlined in 22.2.2.2 [lib.locale.num.put]  template<typename _CharT, typename _OutIter>    template<typename _ValueT>      _OutIter      num_put<_CharT, _OutIter>::      _M_insert_float(_OutIter __s, ios_base& __io, _CharT __fill, char __mod,		       _ValueT __v) const      {	typedef __numpunct_cache<_CharT>                __cache_type;	__use_cache<__cache_type> __uc;	const locale& __loc = __io._M_getloc();	const __cache_type* __lc = __uc(__loc);	// Use default precision if out of range.	streamsize __prec = __io.precision();	if (__prec < static_cast<streamsize>(0))	  __prec = static_cast<streamsize>(6);	const int __max_digits = numeric_limits<_ValueT>::digits10;	// [22.2.2.2.2] Stage 1, numeric conversion to character.	int __len;	// Long enough for the max format spec.	char __fbuf[16];#ifdef _GLIBCXX_USE_C99	// First try a buffer perhaps big enough (most probably sufficient	// for non-ios_base::fixed outputs)	int __cs_size = __max_digits * 3;	char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));	__num_base::_S_format_float(__io, __fbuf, __mod);	__len = std::__convert_from_v(__cs, __cs_size, __fbuf, __v,				      _S_get_c_locale(), __prec);	// If the buffer was not large enough, try again with the correct size.	if (__len >= __cs_size)	  {	    __cs_size = __len + 1;	    __cs = static_cast<char*>(__builtin_alloca(__cs_size));	    __len = std::__convert_from_v(__cs, __cs_size, __fbuf, __v,					  _S_get_c_locale(), __prec);	  }#else	// Consider the possibility of long ios_base::fixed outputs	const bool __fixed = __io.flags() & ios_base::fixed;	const int __max_exp = numeric_limits<_ValueT>::max_exponent10;	// The size of the output string is computed as follows.	// ios_base::fixed outputs may need up to __max_exp + 1 chars	// for the integer part + __prec chars for the fractional part	// + 3 chars for sign, decimal point, '\0'. On the other hand,	// for non-fixed outputs __max_digits * 2 + __prec chars are	// largely sufficient.	const int __cs_size = __fixed ? __max_exp + __prec + 4	                              : __max_digits * 2 + __prec;	char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));	__num_base::_S_format_float(__io, __fbuf, __mod);	__len = std::__convert_from_v(__cs, 0, __fbuf, __v,				      _S_get_c_locale(), __prec);#endif	// [22.2.2.2.2] Stage 2, convert to char_type, using correct	// numpunct.decimal_point() values for '.' and adding grouping.	const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);		_CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)							     * __len));	__ctype.widen(__cs, __cs + __len, __ws);		// Replace decimal point.	const _CharT __cdec = __ctype.widen('.');	const _CharT __dec = __lc->_M_decimal_point;	const _CharT* __p = char_traits<_CharT>::find(__ws, __len, __cdec);	if (__p)	  __ws[__p - __ws] = __dec;		// Add grouping, if necessary.	// N.B. Make sure to not group things like 2e20, i.e., no decimal	// point, scientific notation.	if (__lc->_M_use_grouping	    && (__p || __len < 3 || (__cs[1] <= '9' && __cs[2] <= '9'				     && __cs[1] >= '0' && __cs[2] >= '0')))	  {	    // Grouping can add (almost) as many separators as the	    // number of digits, but no more.	    _CharT* __ws2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)								  * __len * 2));	    	    streamsize __off = 0;	    if (__cs[0] == '-' || __cs[0] == '+')	      {		__off = 1;		__ws2[0] = __ws[0];		__len -= 1;	      }	    	    _M_group_float(__lc->_M_grouping, __lc->_M_grouping_size,			   __lc->_M_thousands_sep, __p, __ws2 + __off,			   __ws + __off, __len);	    __len += __off;	    	    __ws = __ws2;	  }	// Pad.	const streamsize __w = __io.width();	if (__w > static_cast<streamsize>(__len))	  {	    _CharT* __ws3 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)								  * __w));	    _M_pad(__fill, __w, __io, __ws3, __ws, __len);	    __ws = __ws3;	  }	__io.width(0);		// [22.2.2.2.2] Stage 4.	// Write resulting, fully-formatted string to output iterator.	return std::__write(__s, __ws, __len);      }    template<typename _CharT, typename _OutIter>    _OutIter    num_put<_CharT, _OutIter>::    do_put(iter_type __s, ios_base& __io, char_type __fill, bool __v) const    {      const ios_base::fmtflags __flags = __io.flags();      if ((__flags & ios_base::boolalpha) == 0)        {          const long __l = __v;          __s = _M_insert_int(__s, __io, __fill, __l);        }      else        {	  typedef __numpunct_cache<_CharT>              __cache_type;	  __use_cache<__cache_type> __uc;	  const locale& __loc = __io._M_getloc();	  const __cache_type* __lc = __uc(__loc);	  const _CharT* __name = __v ? __lc->_M_truename	                             : __lc->_M_falsename;	  int __len = __v ? __lc->_M_truename_size	                  : __lc->_M_falsename_size;	  const streamsize __w = __io.width();	  if (__w > static_cast<streamsize>(__len))	    {	      _CharT* __cs		= static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)							* __w));	      _M_pad(__fill, __w, __io, __cs, __name, __len);	      __name = __cs;	    }	  __io.width(0);	  __s = std::__write(__s, __name, __len);	}      return __s;    }  template<typename _CharT, typename _OutIter>    _OutIter    num_put<_CharT, _OutIter>::    do_put(iter_type __s, ios_base& __io, char_type __fill, long __v) const    { return _M_insert_int(__s, __io, __fill, __v); }  template<typename _CharT, typename _OutIter>    _OutIter    num_put<_CharT, _OutIter>::    do_put(iter_type __s, ios_base& __io, char_type __fill,           unsigned long __v) const    { return _M_insert_int(__s, __io, __fill, __v); }#ifdef _GLIBCXX_USE_LONG_LONG  template<typename _CharT, typename _OutIter>    _OutIter    num_put<_CharT, _OutIter>::    do_put(iter_type __s, ios_base& __io, char_type __fill, long long __v) const    { return _M_insert_int(__s, __io, __fill, __v); }  template<typename _CharT, typename _OutIter>    _OutIter    num_put<_CharT, _OutIter>::    do_put(iter_type __s, ios_base& __io, char_type __fill,           unsigned long long __v) const    { return _M_insert_int(__s, __io, __fill, __v); }#endif  template<typename _CharT, typename _OutIter>    _OutIter    num_put<_CharT, _OutIter>::    do_put(iter_type __s, ios_base& __io, char_type __fill, double __v) const    { return _M_insert_float(__s, __io, __fill, char(), __v); }  template<typename _CharT, typename _OutIter>    _OutIter    num_put<_CharT, _OutIter>::    do_put(iter_type __s, ios_base& __io, char_type __fill,	   long double __v) const    { return _M_insert_float(__s, __io, __fill, 'L', __v); }  template<typename _CharT, typename _OutIter>    _OutIter    num_put<_CharT, _OutIter>::    do_put(iter_type __s, ios_base& __io, char_type __fill,           const void* __v) const    {      const ios_base::fmtflags __flags = __io.flags();      const ios_base::fmtflags __fmt = ~(ios_base::basefield					 | ios_base::uppercase					 | ios_base::internal);      __io.flags(__flags & __fmt | (ios_base::hex | ios_base::showbase));      __s = _M_insert_int(__s, __io, __fill,			  reinterpret_cast<unsigned long>(__v));      __io.flags(__flags);      return __s;    }  template<typename _CharT, typename _InIter>    template<bool _Intl>      _InIter      money_get<_CharT, _InIter>::      _M_extract(iter_type __beg, iter_type __end, ios_base& __io,		 ios_base::iostate& __err, string& __units) const

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -