const __cache_type* __lc = __uc(__loc);
const _CharT* __lit = __lc->_M_atoms_in;
+ // True if a mantissa is found.
+ bool __found_mantissa = false;
+
// First check for sign.
if (__beg != __end)
{
const char_type __c = *__beg;
const bool __plus = __traits_type::eq(__c, __lit[_S_iplus]);
- if (__plus || __traits_type::eq(__c, __lit[_S_iminus]))
+ if ((__plus || __traits_type::eq(__c, __lit[_S_iminus]))
+ && !__traits_type::eq(__c, __lc->_M_decimal_point)
+ && (!__lc->_M_use_grouping
+ || !__traits_type::eq(__c, __lc->_M_thousands_sep)))
{
__xtrc += __plus ? _S_atoms_in[_S_iplus]
: _S_atoms_in[_S_iminus];
}
}
- // Next, look for a zero...
- bool __found_mantissa = false;
- if (__beg != __end && __traits_type::eq(*__beg, __lit[_S_izero]))
+ // Next, look for leading zeros.
+ while (__beg != __end)
{
- __xtrc += _S_atoms_in[_S_izero];
- __found_mantissa = true;
- ++__beg;
- // ... and skip the additional ones.
- for (; __beg != __end
- && __traits_type::eq(*__beg, __lit[_S_izero]); ++__beg);
+ const char_type __c = *__beg;
+ if (__traits_type::eq(__c, __lc->_M_decimal_point)
+ || (__lc->_M_use_grouping
+ && __traits_type::eq(__c, __lc->_M_thousands_sep)))
+ break;
+ else if (__traits_type::eq(__c, __lit[_S_izero]))
+ {
+ if (!__found_mantissa)
+ {
+ __xtrc += _S_atoms_in[_S_izero];
+ __found_mantissa = true;
+ }
+ ++__beg;
+ }
+ else
+ break;
}
// Only need acceptable digits for floating point numbers.
const char_type* __p;
while (__beg != __end)
{
- // According to 22.2.2.1.2, p8-9, first look for decimal_point
- // and thousands_sep.
+ // According to 22.2.2.1.2, p8-9, first look for thousands_sep
+ // and decimal_point.
const char_type __c = *__beg;
- if (__traits_type::eq(__c, __lc->_M_decimal_point)
- && !__found_dec && !__found_sci)
- {
- // According to the standard, if no grouping chars are seen,
- // no grouping check is applied. Therefore __found_grouping
- // must be adjusted only if __dec comes after some __sep.
- if (__found_grouping.size())
- __found_grouping += static_cast<char>(__sep_pos);
- __xtrc += '.';
- __found_dec = true;
- ++__beg;
- }
- else if (__lc->_M_use_grouping
- && __traits_type::eq(__c, __lc->_M_thousands_sep)
- && !__found_dec && !__found_sci)
+ if (__lc->_M_use_grouping
+ && __traits_type::eq(__c, __lc->_M_thousands_sep))
{
- // NB: Thousands separator at the beginning of a string
- // is a no-no, as is two consecutive thousands separators.
- if (__sep_pos)
- {
- __found_grouping += static_cast<char>(__sep_pos);
- __sep_pos = 0;
- ++__beg;
- }
- else
+ if (!__found_dec && !__found_sci)
{
- __err |= ios_base::failbit;
- break;
+ // NB: Thousands separator at the beginning of a string
+ // is a no-no, as is two consecutive thousands separators.
+ if (__sep_pos)
+ {
+ __found_grouping += static_cast<char>(__sep_pos);
+ __sep_pos = 0;
+ ++__beg;
+ }
+ else
+ {
+ __err |= ios_base::failbit;
+ break;
+ }
}
+ else
+ break;
}
+ else if (__traits_type::eq(__c, __lc->_M_decimal_point))
+ {
+ if (!__found_dec && !__found_sci)
+ {
+ // If no grouping chars are seen, no grouping check
+ // is applied. Therefore __found_grouping is adjusted
+ // only if decimal_point comes after some thousands_sep.
+ if (__found_grouping.size())
+ __found_grouping += static_cast<char>(__sep_pos);
+ __xtrc += '.';
+ __found_dec = true;
+ ++__beg;
+ }
+ else
+ break;
+ }
else if (__p = __traits_type::find(__lit + _S_izero, 10, __c))
{
__xtrc += _S_atoms_in[__p - __lit];
// First check for sign.
bool __negative = false;
if (__beg != __end)
- {
+ {
+ const char_type __c = *__beg;
if (numeric_limits<_ValueT>::is_signed)
- __negative = __traits_type::eq(*__beg, __lit[_S_iminus]);
- if (__negative || __traits_type::eq(*__beg, __lit[_S_iplus]))
+ __negative = __traits_type::eq(__c, __lit[_S_iminus]);
+ if ((__negative || __traits_type::eq(__c, __lit[_S_iplus]))
+ && !__traits_type::eq(__c, __lc->_M_decimal_point)
+ && (!__lc->_M_use_grouping
+ || !__traits_type::eq(__c, __lc->_M_thousands_sep)))
++__beg;
}
// Next, look for leading zeros and check required digits
// for base formats.
- if (__beg != __end && __traits_type::eq(*__beg, __lit[_S_izero]))
+ while (__beg != __end)
{
- __found_num = true;
- ++__beg;
- if (__builtin_expect(__base == 10, true))
+ const char_type __c = *__beg;
+ if (__traits_type::eq(__c, __lc->_M_decimal_point)
+ || (__lc->_M_use_grouping
+ && __traits_type::eq(__c, __lc->_M_thousands_sep)))
+ break;
+ else if (__traits_type::eq(__c, __lit[_S_izero])
+ && (!__found_num || __base == 10))
{
- // Skip the additional zeros.
- for (; __beg != __end
- && __traits_type::eq(*__beg, __lit[_S_izero]); ++__beg);
-
- // Check required digits.
- if (__beg != __end && __basefield == 0)
- {
- const bool __x = __traits_type::eq(*__beg, __lit[_S_ix]);
- if (__x || __traits_type::eq(*__beg, __lit[_S_iX]))
- {
- __base = 16;
- ++__beg;
- __found_num = false;
- }
- else
- __base = 8;
- }
+ __found_num = true;
+ ++__beg;
}
- else if (__base == 16 && __beg != __end)
+ else if (__found_num)
{
- const bool __x = __traits_type::eq(*__beg, __lit[_S_ix]);
- if (__x || __traits_type::eq(*__beg, __lit[_S_iX]))
+ if (__traits_type::eq(__c, __lit[_S_ix])
+ || __traits_type::eq(__c, __lit[_S_iX]))
{
- ++__beg;
- __found_num = false;
+ if (__basefield == 0)
+ __base = 16;
+ if (__base == 16)
+ {
+ __found_num = false;
+ ++__beg;
+ }
}
+ else if (__basefield == 0)
+ __base = 8;
+ break;
}
+ else
+ break;
}
// At this point, base is determined. If not hex, only allow
const _ValueT __min = numeric_limits<_ValueT>::min() / __base;
for (; __beg != __end; ++__beg)
{
- // According to 22.2.2.1.2, p8-9, first look for decimal_point
- // and thousands_sep.
- const char_type __c = *__beg;
- if (__traits_type::eq(__c, __lc->_M_decimal_point))
- break;
- else if (__lc->_M_use_grouping
- && __traits_type::eq(__c, __lc->_M_thousands_sep))
+ // According to 22.2.2.1.2, p8-9, first look for thousands_sep
+ // and decimal_point.
+ const char_type __c = *__beg;
+ if (__lc->_M_use_grouping
+ && __traits_type::eq(__c, __lc->_M_thousands_sep))
{
// NB: Thousands separator at the beginning of a string
// is a no-no, as is two consecutive thousands separators.
break;
}
}
+ else if (__traits_type::eq(__c, __lc->_M_decimal_point))
+ break;
else if (__p = __traits_type::find(__lit_zero, __len, __c))
{
int __digit = __p - __lit_zero;
const _ValueT __max = numeric_limits<_ValueT>::max() / __base;
for (; __beg != __end; ++__beg)
{
- const char_type __c = *__beg;
- if (__traits_type::eq(__c, __lc->_M_decimal_point))
- break;
- else if (__lc->_M_use_grouping
- && __traits_type::eq(__c, __lc->_M_thousands_sep))
+ const char_type __c = *__beg;
+ if (__lc->_M_use_grouping
+ && __traits_type::eq(__c, __lc->_M_thousands_sep))
{
if (__sep_pos)
{
__err |= ios_base::failbit;
break;
}
- }
+ }
+ else if (__traits_type::eq(__c, __lc->_M_decimal_point))
+ break;
else if (__p = __traits_type::find(__lit_zero, __len, __c))
{
int __digit = __p - __lit_zero;
__use_cache<__cache_type> __uc;
const locale& __loc = __io._M_getloc();
const __cache_type* __lc = __uc(__loc);
- const size_t __tn = __traits_type::length(__lc->_M_truename);
- const size_t __fn = __traits_type::length(__lc->_M_falsename);
bool __testf = true;
bool __testt = true;
for (__n = 0; __beg != __end; ++__n, ++__beg)
{
if (__testf)
- if (__n < __fn)
+ if (__n < __lc->_M_falsename_len)
__testf = __traits_type::eq(*__beg, __lc->_M_falsename[__n]);
else
break;
if (__testt)
- if (__n < __tn)
+ if (__n < __lc->_M_truename_len)
__testt = __traits_type::eq(*__beg, __lc->_M_truename[__n]);
else
break;
if (!__testf && !__testt)
break;
}
- if (__testf && __n == __fn)
+ if (__testf && __n == __lc->_M_falsename_len)
__v = 0;
- else if (__testt && __n == __tn)
+ else if (__testt && __n == __lc->_M_truename_len)
__v = 1;
else
__err |= ios_base::failbit;
// Prepare for hex formatted input.
typedef ios_base::fmtflags fmtflags;
const fmtflags __fmt = __io.flags();
- const fmtflags __fmtmask = ~(ios_base::showpos | ios_base::basefield
- | ios_base::uppercase | ios_base::internal);
- __io.flags(__fmt & __fmtmask | (ios_base::hex | ios_base::showbase));
+ __io.flags(__fmt & ~ios_base::basefield | ios_base::hex);
unsigned long __ul;
__beg = _M_extract_int(__beg, __end, __io, __err, __ul);
const _CharT* __name = __v ? __lc->_M_truename
: __lc->_M_falsename;
- int __len = char_traits<_CharT>::length(__name);
+ int __len = __v ? __lc->_M_truename_len
+ : __lc->_M_falsename_len;
const streamsize __w = __io.width();
if (__w > static_cast<streamsize>(__len))
time_get<_CharT, _InIter>::do_date_order() const
{ return time_base::no_order; }
+ // Recursively expand a strftime format string and parse it. Starts w/ %x
+ // and %X from do_get_time() and do_get_date(), which translate to a more
+ // specific string, which may contain yet more strings. I.e. %x => %r =>
+ // %H:%M:%S => extracted characters.
template<typename _CharT, typename _InIter>
void
time_get<_CharT, _InIter>::
bool
__verify_grouping(const basic_string<_CharT>& __grouping,
const basic_string<_CharT>& __grouping_tmp)
- {
- size_t __i = 0;
- size_t __j = 0;
- const size_t __len = __grouping.size();
- const size_t __n = __grouping_tmp.size();
+ {
+ const size_t __n = __grouping_tmp.size() - 1;
+ const size_t __min = std::min(__n, __grouping.size() - 1);
+ size_t __i = __n;
bool __test = true;
-
+
// Parsed number groupings have to match the
// numpunct::grouping string exactly, starting at the
// right-most point of the parsed sequence of elements ...
- while (__test && __i < __n - 1)
- for (__j = 0; __test && __j < __len && __i < __n - 1; ++__j, ++__i)
- __test = __grouping[__j] == __grouping_tmp[__n - __i - 1];
+ for (size_t __j = 0; __j < __min && __test; --__i, ++__j)
+ __test = __grouping_tmp[__i] == __grouping[__j];
+ for (; __i && __test; --__i)
+ __test = __grouping_tmp[__i] == __grouping[__min];
// ... but the last parsed grouping can be <= numpunct
// grouping.
- __j == __len ? __j = 0 : __j;
- __test &= __grouping[__j] >= __grouping_tmp[__n - __i - 1];
+ __test &= __grouping_tmp[0] <= __grouping[__min];
return __test;
}