+ // For use by integer and floating-point types after they have been
+ // converted into a char_type string.
+ template<typename _CharT, typename _OutIter>
+ void
+ num_put<_CharT, _OutIter>::
+ _M_pad(_CharT __fill, streamsize __w, ios_base& __io,
+ _CharT* __new, const _CharT* __cs, int& __len) const
+ {
+ // [22.2.2.2.2] Stage 3.
+ // If necessary, pad.
+ __pad<_CharT, char_traits<_CharT> >::_S_pad(__io, __fill, __new, __cs,
+ __w, __len, true);
+ __len = static_cast<int>(__w);
+ }
+
+ // Forwarding functions to peel signed from unsigned integer types.
+ template<typename _CharT>
+ inline int
+ __int_to_char(_CharT* __bufend, long __v, const _CharT* __lit,
+ ios_base::fmtflags __flags)
+ {
+ unsigned long __ul = static_cast<unsigned long>(__v);
+ bool __neg = false;
+ if (__v < 0)
+ {
+ __ul = -__ul;
+ __neg = true;
+ }
+ return __int_to_char(__bufend, __ul, __lit, __flags, __neg);
+ }
+
+ template<typename _CharT>
+ inline int
+ __int_to_char(_CharT* __bufend, unsigned long __v, const _CharT* __lit,
+ ios_base::fmtflags __flags)
+ { 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 = static_cast<unsigned long long>(__v);
+ bool __neg = false;
+ if (__v < 0)
+ {
+ __ull = -__ull;
+ __neg = true;
+ }
+ return __int_to_char(__bufend, __ull, __lit, __flags, __neg);
+ }
+
+ 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
+
+ template<typename _CharT, typename _ValueT>
+ int
+ __int_to_char(_CharT* __bufend, _ValueT __v, const _CharT* __lit,
+ ios_base::fmtflags __flags, bool __neg)
+ {
+ // Don't write base if already 0.
+ const bool __showbase = (__flags & ios_base::showbase) && __v;
+ const ios_base::fmtflags __basefield = __flags & ios_base::basefield;
+ _CharT* __buf = __bufend - 1;
+
+ 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);
+ if (__neg)
+ *__buf-- = __lit[__num_base::_S_ominus];
+ else if (__flags & ios_base::showpos)
+ *__buf-- = __lit[__num_base::_S_oplus];
+ }
+ else if (__basefield == ios_base::oct)
+ {
+ // Octal.
+ do
+ {
+ *__buf-- = __lit[(__v & 0x7) + __num_base::_S_odigits];
+ __v >>= 3;
+ }
+ while (__v != 0);
+ if (__showbase)
+ *__buf-- = __lit[__num_base::_S_odigits];
+ }
+ 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);
+ if (__showbase)
+ {
+ // 'x' or 'X'
+ *__buf-- = __lit[__num_base::_S_ox + __uppercase];
+ // '0'
+ *__buf-- = __lit[__num_base::_S_odigits];
+ }
+ }
+ return __bufend - __buf - 1;
+ }
+
+ template<typename _CharT, typename _OutIter>
+ void
+ num_put<_CharT, _OutIter>::
+ _M_group_int(const string& __grouping, _CharT __sep, ios_base& __io,
+ _CharT* __new, _CharT* __cs, int& __len) const
+ {
+ // By itself __add_grouping cannot deal correctly with __cs when
+ // ios::showbase is set and ios_base::oct || ios_base::hex.
+ // Therefore we take care "by hand" of the initial 0, 0x or 0X.
+ // However, remember that the latter do not occur if the number
+ // printed is '0' (__len == 1).
+ streamsize __off = 0;
+ const ios_base::fmtflags __basefield = __io.flags()
+ & ios_base::basefield;
+ if ((__io.flags() & ios_base::showbase) && __len > 1)
+ if (__basefield == ios_base::oct)
+ {
+ __off = 1;
+ __new[0] = __cs[0];
+ }
+ else if (__basefield == ios_base::hex)
+ {
+ __off = 2;
+ __new[0] = __cs[0];
+ __new[1] = __cs[1];
+ }
+ _CharT* __p;
+ __p = std::__add_grouping(__new + __off, __sep, __grouping.data(),
+ __grouping.data() + __grouping.size(),
+ __cs + __off, __cs + __len);
+ __len = __p - __new;
+ }
+