- __s = _M_convert_int(__s, __io, __fill, 'u', char(),
- reinterpret_cast<unsigned long>(__v));
- __io.flags(__flags);
- }
- catch (...)
- {
- __io.flags(__flags);
- __throw_exception_again;
- }
- return __s;
- }
-
-
- template<typename _CharT, typename _InIter>
- _InIter
- money_get<_CharT, _InIter>::
- do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io,
- ios_base::iostate& __err, long double& __units) const
- {
- string_type __str;
- __beg = this->do_get(__beg, __end, __intl, __io, __err, __str);
-
- const int __n = numeric_limits<long double>::digits10;
- char* __cs = static_cast<char*>(__builtin_alloca(__n));
- const locale __loc = __io.getloc();
- const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
- const _CharT* __wcs = __str.c_str();
- __ctype.narrow(__wcs, __wcs + __str.size() + 1, char(), __cs);
- __convert_to_v(__cs, __units, __err, _S_c_locale);
- return __beg;
- }
-
- template<typename _CharT, typename _InIter>
- _InIter
- money_get<_CharT, _InIter>::
- do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io,
- ios_base::iostate& __err, string_type& __units) const
- {
- // These contortions are quite unfortunate.
- typedef moneypunct<_CharT, true> __money_true;
- typedef moneypunct<_CharT, false> __money_false;
- typedef money_base::part part;
- typedef typename string_type::size_type size_type;
-
- const locale __loc = __io.getloc();
- const __money_true& __mpt = use_facet<__money_true>(__loc);
- const __money_false& __mpf = use_facet<__money_false>(__loc);
- const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
-
- const money_base::pattern __p = __intl ? __mpt.neg_format()
- : __mpf.neg_format();
-
- const string_type __pos_sign =__intl ? __mpt.positive_sign()
- : __mpf.positive_sign();
- const string_type __neg_sign =__intl ? __mpt.negative_sign()
- : __mpf.negative_sign();
- const char_type __d = __intl ? __mpt.decimal_point()
- : __mpf.decimal_point();
- const char_type __sep = __intl ? __mpt.thousands_sep()
- : __mpf.thousands_sep();
-
- const string __grouping = __intl ? __mpt.grouping() : __mpf.grouping();
-
- // Set to deduced positive or negative sign, depending.
- string_type __sign;
- // String of grouping info from thousands_sep plucked from __units.
- string __grouping_tmp;
- // Marker for thousands_sep position.
- int __sep_pos = 0;
- // If input iterator is in a valid state.
- bool __testvalid = true;
- // Flag marking when a decimal point is found.
- bool __testdecfound = false;
-
- // The tentative returned string is stored here.
- string_type __temp_units;
-
- char_type __c = *__beg;
- char_type __eof = static_cast<char_type>(char_traits<char_type>::eof());
- for (int __i = 0; __beg != __end && __i < 4 && __testvalid; ++__i)
- {
- part __which = static_cast<part>(__p.field[__i]);
- switch (__which)
- {
- case money_base::symbol:
- if (__io.flags() & ios_base::showbase
- || __i < 2 || __sign.size() > 1
- || ((static_cast<part>(__p.field[3]) != money_base::none)
- && __i == 2))
- {
- // According to 22.2.6.1.2.2, symbol is required
- // if (__io.flags() & ios_base::showbase),
- // otherwise is optional and consumed only if
- // other characters are needed to complete the
- // format.
- const string_type __symbol = __intl ? __mpt.curr_symbol()
- : __mpf.curr_symbol();
- size_type __len = __symbol.size();
- size_type __j = 0;
- while (__beg != __end
- && __j < __len && __symbol[__j] == __c)
- {
- __c = *(++__beg);
- ++__j;
- }
- // When (__io.flags() & ios_base::showbase)
- // symbol is required.
- if (__j != __len && (__io.flags() & ios_base::showbase))
- __testvalid = false;
- }
- break;
- case money_base::sign:
- // Sign might not exist, or be more than one character long.
- if (__pos_sign.size() && __neg_sign.size())
- {
- // Sign is mandatory.
- if (__c == __pos_sign[0])
- {
- __sign = __pos_sign;
- __c = *(++__beg);
- }
- else if (__c == __neg_sign[0])
- {
- __sign = __neg_sign;
- __c = *(++__beg);
- }
- else
- __testvalid = false;
- }
- else if (__pos_sign.size() && __c == __pos_sign[0])
- {
- __sign = __pos_sign;
- __c = *(++__beg);
- }
- else if (__neg_sign.size() && __c == __neg_sign[0])
- {
- __sign = __neg_sign;
- __c = *(++__beg);
- }
- break;
- case money_base::value:
- // Extract digits, remove and stash away the
- // grouping of found thousands separators.
- while (__beg != __end
- && (__ctype.is(ctype_base::digit, __c)
- || (__c == __d && !__testdecfound)
- || __c == __sep))
- {
- if (__c == __d)
- {
- __grouping_tmp += static_cast<char>(__sep_pos);
- __sep_pos = 0;
- __testdecfound = true;
- }
- else if (__c == __sep)
- {
- if (__grouping.size())
- {
- // Mark position for later analysis.
- __grouping_tmp += static_cast<char>(__sep_pos);
- __sep_pos = 0;
- }
- else
- {
- __testvalid = false;
- break;
- }
- }
- else
- {
- __temp_units += __c;
- ++__sep_pos;
- }
- __c = *(++__beg);
- }
- break;
- case money_base::space:
- case money_base::none:
- // Only if not at the end of the pattern.
- if (__i != 3)
- while (__beg != __end
- && __ctype.is(ctype_base::space, __c))
- __c = *(++__beg);
- break;
- }
- }
-
- // Need to get the rest of the sign characters, if they exist.
- if (__sign.size() > 1)
- {
- size_type __len = __sign.size();
- size_type __i = 1;
- for (; __c != __eof && __i < __len; ++__i)
- while (__beg != __end && __c != __sign[__i])
- __c = *(++__beg);
-
- if (__i != __len)
- __testvalid = false;
- }
-
- // Strip leading zeros.
- while (__temp_units[0] == __ctype.widen('0'))
- __temp_units.erase(__temp_units.begin());
-
- if (__sign.size() && __sign == __neg_sign)
- __temp_units.insert(__temp_units.begin(), __ctype.widen('-'));
-
- // Test for grouping fidelity.
- if (__grouping.size() && __grouping_tmp.size())
- {
- if (!__verify_grouping(__grouping, __grouping_tmp))
- __testvalid = false;
- }
-
- // Iff no more characters are available.
- if (__c == __eof)
- __err |= ios_base::eofbit;
-
- // Iff valid sequence is not recognized.
- if (!__testvalid || !__temp_units.size())
- __err |= ios_base::failbit;
- else
- // Use the "swap trick" to copy __temp_units into __units.
- __temp_units.swap(__units);
-
- return __beg;
- }
-
- template<typename _CharT, typename _OutIter>
- _OutIter
- money_put<_CharT, _OutIter>::
- do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
- long double __units) const
- {
- const locale __loc = __io.getloc();
- const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
-#ifdef _GLIBCPP_USE_C99
- // First try a buffer perhaps big enough.
- int __cs_size = 64;
- char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
- int __len = __convert_from_v(__cs, __cs_size, "%.01Lf", __units,
- _S_c_locale);
- // 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 = __convert_from_v(__cs, __cs_size, "%.01Lf", __units,
- _S_c_locale);
- }
-#else
- // max_exponent10 + 1 for the integer part, + 4 for sign, decimal point,
- // decimal digit, '\0'.
- const int __cs_size = numeric_limits<long double>::max_exponent10 + 5;
- char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
- int __len = __convert_from_v(__cs, 0, "%.01Lf", __units, _S_c_locale);
-#endif
- _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __cs_size));
- __ctype.widen(__cs, __cs + __len, __ws);
- string_type __digits(__ws);
- return this->do_put(__s, __intl, __io, __fill, __digits);
- }
-
- template<typename _CharT, typename _OutIter>
- _OutIter
- money_put<_CharT, _OutIter>::
- do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
- const string_type& __digits) const
- {
- typedef typename string_type::size_type size_type;
- typedef money_base::part part;
-
- const locale __loc = __io.getloc();
- const size_type __width = static_cast<size_type>(__io.width());
-
- // These contortions are quite unfortunate.
- typedef moneypunct<_CharT, true> __money_true;
- typedef moneypunct<_CharT, false> __money_false;
- const __money_true& __mpt = use_facet<__money_true>(__loc);
- const __money_false& __mpf = use_facet<__money_false>(__loc);
- const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
-
- // Determine if negative or positive formats are to be used, and
- // discard leading negative_sign if it is present.
- const char_type* __beg = __digits.data();
- const char_type* __end = __beg + __digits.size();
- money_base::pattern __p;
- string_type __sign;
- if (*__beg != __ctype.widen('-'))
- {
- __p = __intl ? __mpt.pos_format() : __mpf.pos_format();
- __sign =__intl ? __mpt.positive_sign() : __mpf.positive_sign();
- }
- else
- {
- __p = __intl ? __mpt.neg_format() : __mpf.neg_format();
- __sign =__intl ? __mpt.negative_sign() : __mpf.negative_sign();
- ++__beg;
- }
-
- // Look for valid numbers in the current ctype facet within input digits.
- __end = __ctype.scan_not(ctype_base::digit, __beg, __end);
- if (__beg != __end)
- {
- // Assume valid input, and attempt to format.
- // Break down input numbers into base components, as follows:
- // final_value = grouped units + (decimal point) + (digits)
- string_type __res;
- string_type __value;
- const string_type __symbol = __intl ? __mpt.curr_symbol()
- : __mpf.curr_symbol();
-
- // Deal with decimal point, decimal digits.
- const int __frac = __intl ? __mpt.frac_digits()
- : __mpf.frac_digits();
- if (__frac > 0)
- {
- const char_type __d = __intl ? __mpt.decimal_point()
- : __mpf.decimal_point();
- if (__end - __beg >= __frac)
- {
- __value = string_type(__end - __frac, __end);
- __value.insert(__value.begin(), __d);
- __end -= __frac;
- }
- else
- {
- // Have to pad zeros in the decimal position.
- __value = string_type(__beg, __end);
- int __paddec = __frac - (__end - __beg);
- char_type __zero = __ctype.widen('0');
- __value.insert(__value.begin(), __paddec, __zero);
- __value.insert(__value.begin(), __d);
- __beg = __end;
- }
- }
-
- // Add thousands separators to non-decimal digits, per
- // grouping rules.
- if (__beg != __end)
- {
- const string __grouping = __intl ? __mpt.grouping()
- : __mpf.grouping();
- if (__grouping.size())
- {
- const char_type __sep = __intl ? __mpt.thousands_sep()
- : __mpf.thousands_sep();
- const char* __gbeg = __grouping.c_str();
- const char* __gend = __gbeg + __grouping.size();
- const int __n = (__end - __beg) * 2;
- _CharT* __ws2 =
- static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __n));
- _CharT* __ws_end = __add_grouping(__ws2, __sep, __gbeg,
- __gend, __beg, __end);
- __value.insert(0, __ws2, __ws_end - __ws2);
- }
- else
- __value.insert(0, string_type(__beg, __end));
- }
-
- // Calculate length of resulting string.
- ios_base::fmtflags __f = __io.flags() & ios_base::adjustfield;
- size_type __len = __value.size() + __sign.size();
- __len += (__io.flags() & ios_base::showbase) ? __symbol.size() : 0;
- bool __testipad = __f == ios_base::internal && __len < __width;
-
- // Fit formatted digits into the required pattern.
- for (int __i = 0; __i < 4; ++__i)
- {
- part __which = static_cast<part>(__p.field[__i]);
- switch (__which)
- {
- case money_base::symbol:
- if (__io.flags() & ios_base::showbase)
- __res += __symbol;
- break;
- case money_base::sign:
- // Sign might not exist, or be more than one
- // charater long. In that case, add in the rest
- // below.
- if (__sign.size())
- __res += __sign[0];
- break;
- case money_base::value:
- __res += __value;
- break;
- case money_base::space:
- // At least one space is required, but if internal
- // formatting is required, an arbitrary number of
- // fill spaces will be necessary.
- if (__testipad)
- __res += string_type(__width - __len, __fill);
- else
- __res += __ctype.widen(__fill);
- break;
- case money_base::none:
- if (__testipad)
- __res += string_type(__width - __len, __fill);
- break;
- }
- }
-
- // Special case of multi-part sign parts.
- if (__sign.size() > 1)
- __res += string_type(__sign.begin() + 1, __sign.end());
-
- // Pad, if still necessary.
- __len = __res.size();
- if (__width > __len)