// Locale support -*- C++ -*-
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// Warning: this file is not meant for user inclusion. Use <locale>.
-#ifndef _CPP_BITS_LOCFACETS_TCC
-#define _CPP_BITS_LOCFACETS_TCC 1
+#ifndef _LOCALE_FACETS_TCC
+#define _LOCALE_FACETS_TCC 1
#pragma GCC system_header
-#include <cerrno>
-#include <clocale> // For localeconv
-#include <cstdlib> // For strof, strtold
-#include <cmath> // For ceil
-#include <cctype> // For isspace
-#include <limits> // For numeric_limits
+#include <limits> // For numeric_limits
+#include <typeinfo> // For bad_cast.
#include <bits/streambuf_iterator.h>
-#include <typeinfo> // For bad_cast.
namespace std
{
locale::combine(const locale& __other) const
{
_Impl* __tmp = new _Impl(*_M_impl, 1);
- __tmp->_M_replace_facet(__other._M_impl, &_Facet::id);
+ try
+ {
+ __tmp->_M_replace_facet(__other._M_impl, &_Facet::id);
+ }
+ catch(...)
+ {
+ __tmp->_M_remove_reference();
+ __throw_exception_again;
+ }
return locale(__tmp);
}
__s2.data(), __s2.data() + __s2.length()) < 0);
}
+ /**
+ * @brief Test for the presence of a facet.
+ *
+ * has_facet tests the locale argument for the presence of the facet type
+ * provided as the template parameter. Facets derived from the facet
+ * parameter will also return true.
+ *
+ * @param Facet The facet type to test the presence of.
+ * @param locale The locale to test.
+ * @return true if locale contains a facet of type Facet, else false.
+ * @throw std::bad_cast if locale doesn't contain the facet.
+ */
+ template<typename _Facet>
+ inline bool
+ has_facet(const locale& __loc) throw()
+ {
+ const size_t __i = _Facet::id._M_id();
+ const locale::facet** __facets = __loc._M_impl->_M_facets;
+ return (__i < __loc._M_impl->_M_facets_size && __facets[__i]);
+ }
+
+ /**
+ * @brief Return a facet.
+ *
+ * use_facet looks for and returns a reference to a facet of type Facet
+ * where Facet is the template parameter. If has_facet(locale) is true,
+ * there is a suitable facet to return. It throws std::bad_cast if the
+ * locale doesn't contain a facet of type Facet.
+ *
+ * @param Facet The facet type to access.
+ * @param locale The locale to use.
+ * @return Reference to facet of type Facet.
+ * @throw std::bad_cast if locale doesn't contain a facet of type Facet.
+ */
template<typename _Facet>
- const _Facet&
+ inline const _Facet&
use_facet(const locale& __loc)
{
- size_t __i = _Facet::id._M_id();
- locale::facet** __facets = __loc._M_impl->_M_facets;
+ const size_t __i = _Facet::id._M_id();
+ const locale::facet** __facets = __loc._M_impl->_M_facets;
if (!(__i < __loc._M_impl->_M_facets_size && __facets[__i]))
__throw_bad_cast();
return static_cast<const _Facet&>(*__facets[__i]);
}
+ // Routine to access a cache for the facet. If the cache didn't
+ // exist before, it gets constructed on the fly.
template<typename _Facet>
- bool
- has_facet(const locale& __loc) throw()
+ struct __use_cache
{
- size_t __i = _Facet::id._M_id();
- locale::facet** __facets = __loc._M_impl->_M_facets;
- return (__i < __loc._M_impl->_M_facets_size && __facets[__i]);
- }
+ const _Facet*
+ operator() (const locale& __loc) const;
+ };
+ template<typename _CharT>
+ struct __use_cache<__numpunct_cache<_CharT> >
+ {
+ const __numpunct_cache<_CharT>*
+ operator() (const locale& __loc) const
+ {
+ const size_t __i = numpunct<_CharT>::id._M_id();
+ const locale::facet** __caches = __loc._M_impl->_M_caches;
+ if (!__caches[__i])
+ {
+ __numpunct_cache<_CharT>* __tmp = NULL;
+ try
+ {
+ __tmp = new __numpunct_cache<_CharT>;
+ __tmp->_M_cache(__loc);
+ }
+ catch(...)
+ {
+ delete __tmp;
+ __throw_exception_again;
+ }
+ __loc._M_impl->_M_install_cache(__tmp, __i);
+ }
+ return static_cast<const __numpunct_cache<_CharT>*>(__caches[__i]);
+ }
+ };
- // Stage 1: Determine a conversion specifier.
template<typename _CharT, typename _InIter>
_InIter
num_get<_CharT, _InIter>::
_M_extract_float(_InIter __beg, _InIter __end, ios_base& __io,
ios_base::iostate& __err, string& __xtrc) const
{
- typedef char_traits<_CharT> __traits_type;
- const locale __loc = __io.getloc();
- const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
- const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
+ typedef char_traits<_CharT> __traits_type;
+ typedef typename numpunct<_CharT>::__cache_type __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_in;
- // First check for sign.
- const char_type __plus = __ctype.widen('+');
- const char_type __minus = __ctype.widen('-');
- int __pos = 0;
- char_type __c = *__beg;
- if ((__traits_type::eq(__c, __plus) || __traits_type::eq(__c, __minus))
- && __beg != __end)
- {
- __xtrc += __ctype.narrow(__c, char());
- ++__pos;
- __c = *(++__beg);
- }
+ // True if a mantissa is found.
+ bool __found_mantissa = false;
- // Next, strip leading zeros.
- const char_type __zero = __ctype.widen(_S_atoms[_M_zero]);
- bool __found_zero = false;
- while (__traits_type::eq(__c, __zero) && __beg != __end)
+ // First check for sign.
+ if (__beg != __end)
{
- __c = *(++__beg);
- __found_zero = true;
+ const char_type __c = *__beg;
+ const bool __plus = __traits_type::eq(__c, __lit[_S_iplus]);
+ 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];
+ ++__beg;
+ }
}
- if (__found_zero)
+
+ // Next, look for leading zeros.
+ while (__beg != __end)
{
- __xtrc += _S_atoms[_M_zero];
- ++__pos;
+ 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 size_t __len = _M_E - _M_zero + 1;
- char_type __watoms[__len];
- __ctype.widen(_S_atoms, _S_atoms + __len, __watoms);
bool __found_dec = false;
bool __found_sci = false;
- const char_type __dec = __np.decimal_point();
-
string __found_grouping;
- const string __grouping = __np.grouping();
- bool __check_grouping = __grouping.size();
int __sep_pos = 0;
- const char_type __sep = __np.thousands_sep();
-
+ bool __e;
+ const char_type* __p;
while (__beg != __end)
{
- // Only look in digits.
- const char_type* __p = __traits_type::find(__watoms, 10, __c);
-
- // NB: strchr returns true for __c == 0x0
- if (__p && !__traits_type::eq(__c, char_type()))
+ // 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))
{
- // Try first for acceptable digit; record it if found.
- ++__pos;
- __xtrc += _S_atoms[__p - __watoms];
- ++__sep_pos;
- __c = *(++__beg);
- }
- else if (__traits_type::eq(__c, __sep)
- && __check_grouping && !__found_dec)
- {
- // 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;
- __c = *(++__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, __dec) && !__found_dec)
+ else if (__traits_type::eq(__c, __lc->_M_decimal_point))
{
- // 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);
- ++__pos;
- __xtrc += '.';
- __c = *(++__beg);
- __found_dec = true;
+ 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 ((__traits_type::eq(__c, __watoms[_M_e])
- || __traits_type::eq(__c, __watoms[_M_E]))
- && !__found_sci && __pos)
+ else if (__p = __traits_type::find(__lit + _S_izero, 10, __c))
+ {
+ __xtrc += _S_atoms_in[__p - __lit];
+ __found_mantissa = true;
+ ++__sep_pos;
+ ++__beg;
+ }
+ else if ((__e = __traits_type::eq(__c, __lit[_S_ie])
+ || __traits_type::eq(__c, __lit[_S_iE]))
+ && __found_mantissa && !__found_sci)
{
// Scientific notation.
- ++__pos;
- __xtrc += __ctype.narrow(__c, char());
- __c = *(++__beg);
+ __xtrc += __e ? _S_atoms_in[_S_ie] : _S_atoms_in[_S_iE];
+ __found_sci = true;
// Remove optional plus or minus sign, if they exist.
- if (__traits_type::eq(__c, __plus)
- || __traits_type::eq(__c, __minus))
+ if (++__beg != __end)
{
- ++__pos;
- __xtrc += __ctype.narrow(__c, char());
- __c = *(++__beg);
+ const bool __plus = __traits_type::eq(*__beg, __lit[_S_iplus]);
+ if (__plus || __traits_type::eq(*__beg, __lit[_S_iminus]))
+ {
+ __xtrc += __plus ? _S_atoms_in[_S_iplus]
+ : _S_atoms_in[_S_iminus];
+ ++__beg;
+ }
}
- __found_sci = true;
}
else
// Not a valid input item.
// Digit grouping is checked. If grouping and found_grouping don't
// match, then get very very upset, and set failbit.
- if (__check_grouping && __found_grouping.size())
+ if (__lc->_M_use_grouping && __found_grouping.size())
{
// Add the ending grouping if a decimal wasn't found.
if (!__found_dec)
__found_grouping += static_cast<char>(__sep_pos);
- if (!__verify_grouping(__grouping, __found_grouping))
+
+ const string __grouping = __lc->_M_grouping;
+ if (!std::__verify_grouping(__grouping, __found_grouping))
__err |= ios_base::failbit;
}
- // Finish up
+ // Finish up.
__xtrc += char();
if (__beg == __end)
__err |= ios_base::eofbit;
return __beg;
}
- // Stage 1: Determine a conversion specifier.
template<typename _CharT, typename _InIter>
- _InIter
- num_get<_CharT, _InIter>::
- _M_extract_int(_InIter __beg, _InIter __end, ios_base& __io,
- ios_base::iostate& __err, string& __xtrc, int& __base) const
- {
- typedef char_traits<_CharT> __traits_type;
- const locale __loc = __io.getloc();
- const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
- const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
-
- // NB: Iff __basefield == 0, this can change based on contents.
- ios_base::fmtflags __basefield = __io.flags() & ios_base::basefield;
- if (__basefield == ios_base::oct)
- __base = 8;
- else if (__basefield == ios_base::hex)
- __base = 16;
- else
- __base = 10;
-
- // First check for sign.
- int __pos = 0;
- char_type __c = *__beg;
- const char_type __plus = __ctype.widen('+');
- const char_type __minus = __ctype.widen('-');
-
- if ((__traits_type::eq(__c, __plus) || __traits_type::eq(__c, __minus))
- && __beg != __end)
- {
- __xtrc += __ctype.narrow(__c, char());
- ++__pos;
- __c = *(++__beg);
- }
+ template<typename _ValueT>
+ _InIter
+ num_get<_CharT, _InIter>::
+ _M_extract_int(_InIter __beg, _InIter __end, ios_base& __io,
+ ios_base::iostate& __err, _ValueT& __v) const
+ {
+ typedef char_traits<_CharT> __traits_type;
+ typedef typename numpunct<_CharT>::__cache_type __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_in;
+
+ // NB: Iff __basefield == 0, __base can change based on contents.
+ const ios_base::fmtflags __basefield = __io.flags() & ios_base::basefield;
+ const bool __oct = __basefield == ios_base::oct;
+ int __base = __oct ? 8 : (__basefield == ios_base::hex ? 16 : 10);
+
+ // True if numeric digits are found.
+ bool __found_num = false;
+
+ // 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(__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, strip leading zeros and check required digits for base formats.
- const char_type __zero = __ctype.widen(_S_atoms[_M_zero]);
- const char_type __x = __ctype.widen('x');
- const char_type __X = __ctype.widen('X');
- if (__base == 10)
- {
- bool __found_zero = false;
- while (__traits_type::eq(__c, __zero) && __beg != __end)
- {
- __c = *(++__beg);
- __found_zero = true;
- }
- if (__found_zero)
- {
- __xtrc += _S_atoms[_M_zero];
- ++__pos;
- if (__basefield == 0)
- {
- if ((__traits_type::eq(__c, __x)
- || __traits_type::eq(__c, __X))
- && __beg != __end)
- {
- __xtrc += __ctype.narrow(__c, char());
- ++__pos;
- __c = *(++__beg);
+ // Next, look for leading zeros and check required digits
+ // for base formats.
+ while (__beg != __end)
+ {
+ 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))
+ {
+ __found_num = true;
+ ++__beg;
+ }
+ else if (__found_num)
+ {
+ if (__traits_type::eq(__c, __lit[_S_ix])
+ || __traits_type::eq(__c, __lit[_S_iX]))
+ {
+ if (__basefield == 0)
__base = 16;
- }
- else
- __base = 8;
- }
- }
- }
- else if (__base == 16)
- {
- if (__traits_type::eq(__c, __zero) && __beg != __end)
- {
- __xtrc += _S_atoms[_M_zero];
- ++__pos;
- __c = *(++__beg);
- if ((__traits_type::eq(__c, __x) || __traits_type::eq(__c, __X))
- && __beg != __end)
- {
- __xtrc += __ctype.narrow(__c, char());
- ++__pos;
- __c = *(++__beg);
- }
- }
- }
-
- // At this point, base is determined. If not hex, only allow
- // base digits as valid input.
- size_t __len;
- if (__base == 16)
- __len = _M_size;
- else
- __len = __base;
-
- // Extract.
- char_type __watoms[_M_size];
- __ctype.widen(_S_atoms, _S_atoms + __len, __watoms);
- string __found_grouping;
- const string __grouping = __np.grouping();
- bool __check_grouping = __grouping.size();
- int __sep_pos = 0;
- const char_type __sep = __np.thousands_sep();
- while (__beg != __end)
- {
- const char_type* __p = __traits_type::find(__watoms, __len, __c);
+ if (__base == 16)
+ {
+ __found_num = false;
+ ++__beg;
+ }
+ }
+ else if (__basefield == 0)
+ __base = 8;
+ break;
+ }
+ else
+ break;
+ }
- // NB: strchr returns true for __c == 0x0
- if (__p && !__traits_type::eq(__c, char_type()))
- {
- // Try first for acceptable digit; record it if found.
- __xtrc += _S_atoms[__p - __watoms];
- ++__pos;
- ++__sep_pos;
- __c = *(++__beg);
- }
- else if (__traits_type::eq(__c, __sep) && __check_grouping)
- {
- // 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;
- __c = *(++__beg);
- }
- else
- {
- __err |= ios_base::failbit;
+ // At this point, base is determined. If not hex, only allow
+ // base digits as valid input.
+ const size_t __len = __base == 16 ? _S_iend : __base;
+
+ // Extract.
+ string __found_grouping;
+ int __sep_pos = 0;
+ bool __overflow = false;
+ _ValueT __result = 0;
+ const char_type* __lit_zero = __lit + _S_izero;
+ const char_type* __p;
+ if (__negative)
+ {
+ const _ValueT __min = numeric_limits<_ValueT>::min() / __base;
+ for (; __beg != __end; ++__beg)
+ {
+ // 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.
+ if (__sep_pos)
+ {
+ __found_grouping += static_cast<char>(__sep_pos);
+ __sep_pos = 0;
+ }
+ else
+ {
+ __err |= ios_base::failbit;
+ break;
+ }
+ }
+ else if (__traits_type::eq(__c, __lc->_M_decimal_point))
break;
- }
- }
- else
- // Not a valid input item.
- break;
- }
+ else if (__p = __traits_type::find(__lit_zero, __len, __c))
+ {
+ int __digit = __p - __lit_zero;
+ if (__digit > 15)
+ __digit -= 6;
+ if (__result < __min)
+ __overflow = true;
+ else
+ {
+ const _ValueT __new_result = __result * __base - __digit;
+ __overflow |= __new_result > __result;
+ __result = __new_result;
+ ++__sep_pos;
+ __found_num = true;
+ }
+ }
+ else
+ // Not a valid input item.
+ break;
+ }
+ }
+ else
+ {
+ const _ValueT __max = numeric_limits<_ValueT>::max() / __base;
+ for (; __beg != __end; ++__beg)
+ {
+ const char_type __c = *__beg;
+ if (__lc->_M_use_grouping
+ && __traits_type::eq(__c, __lc->_M_thousands_sep))
+ {
+ if (__sep_pos)
+ {
+ __found_grouping += static_cast<char>(__sep_pos);
+ __sep_pos = 0;
+ }
+ else
+ {
+ __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;
+ if (__digit > 15)
+ __digit -= 6;
+ if (__result > __max)
+ __overflow = true;
+ else
+ {
+ const _ValueT __new_result = __result * __base + __digit;
+ __overflow |= __new_result < __result;
+ __result = __new_result;
+ ++__sep_pos;
+ __found_num = true;
+ }
+ }
+ else
+ break;
+ }
+ }
- // Digit grouping is checked. If grouping and found_grouping don't
- // match, then get very very upset, and set failbit.
- if (__check_grouping && __found_grouping.size())
- {
- // Add the ending grouping.
- __found_grouping += static_cast<char>(__sep_pos);
- if (!__verify_grouping(__grouping, __found_grouping))
- __err |= ios_base::failbit;
- }
+ // Digit grouping is checked. If grouping and found_grouping don't
+ // match, then get very very upset, and set failbit.
+ if (__lc->_M_use_grouping && __found_grouping.size())
+ {
+ // Add the ending grouping.
+ __found_grouping += static_cast<char>(__sep_pos);
+
+ const string __grouping = __lc->_M_grouping;
+ if (!std::__verify_grouping(__grouping, __found_grouping))
+ __err |= ios_base::failbit;
+ }
- // Finish up.
- __xtrc += char();
- if (__beg == __end)
- __err |= ios_base::eofbit;
- return __beg;
- }
+ if (!(__err & ios_base::failbit) && !__overflow
+ && __found_num)
+ __v = __result;
+ else
+ __err |= ios_base::failbit;
-#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
- //17. Bad bool parsing
+ if (__beg == __end)
+ __err |= ios_base::eofbit;
+ return __beg;
+ }
+
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 17. Bad bool parsing
template<typename _CharT, typename _InIter>
_InIter
num_get<_CharT, _InIter>::
do_get(iter_type __beg, iter_type __end, ios_base& __io,
ios_base::iostate& __err, bool& __v) const
{
- // Parse bool values as unsigned long
if (!(__io.flags() & ios_base::boolalpha))
{
+ // Parse bool values as long.
// NB: We can't just call do_get(long) here, as it might
// refer to a derived class.
- string __xtrc;
- int __base;
- __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base);
-
- unsigned long __ul;
- __convert_to_v(__xtrc.c_str(), __ul, __err, _S_c_locale, __base);
- if (!(__err & ios_base::failbit) && __ul <= 1)
- __v = __ul;
- else
+ long __l = -1;
+ __beg = _M_extract_int(__beg, __end, __io, __err, __l);
+ if (__l == 0 || __l == 1)
+ __v = __l;
+ else
__err |= ios_base::failbit;
}
-
- // Parse bool values as alphanumeric
else
{
- typedef char_traits<_CharT> __traits_type;
- typedef basic_string<_CharT> __string_type;
-
- locale __loc = __io.getloc();
- const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
- const __string_type __true = __np.truename();
- const __string_type __false = __np.falsename();
- const char_type* __trues = __true.c_str();
- const char_type* __falses = __false.c_str();
- const size_t __truen = __true.size() - 1;
- const size_t __falsen = __false.size() - 1;
-
- for (size_t __n = 0; __beg != __end; ++__n)
+ // Parse bool values as alphanumeric.
+ typedef char_traits<_CharT> __traits_type;
+ typedef typename numpunct<_CharT>::__cache_type __cache_type;
+ __use_cache<__cache_type> __uc;
+ const locale& __loc = __io._M_getloc();
+ const __cache_type* __lc = __uc(__loc);
+
+ bool __testf = true;
+ bool __testt = true;
+ size_t __n;
+ for (__n = 0; __beg != __end; ++__n, ++__beg)
{
- char_type __c = *__beg++;
- bool __testf = __n <= __falsen
- ? __traits_type::eq(__c, __falses[__n]) : false;
- bool __testt = __n <= __truen
- ? __traits_type::eq(__c, __trues[__n]) : false;
- if (!(__testf || __testt))
- {
- __err |= ios_base::failbit;
- break;
- }
- else if (__testf && __n == __falsen)
- {
- __v = 0;
- break;
- }
- else if (__testt && __n == __truen)
- {
- __v = 1;
- break;
- }
+ if (__testf)
+ if (__n < __lc->_M_falsename_len)
+ __testf = __traits_type::eq(*__beg, __lc->_M_falsename[__n]);
+ else
+ break;
+
+ if (__testt)
+ if (__n < __lc->_M_truename_len)
+ __testt = __traits_type::eq(*__beg, __lc->_M_truename[__n]);
+ else
+ break;
+
+ if (!__testf && !__testt)
+ break;
}
+ if (__testf && __n == __lc->_M_falsename_len)
+ __v = 0;
+ else if (__testt && __n == __lc->_M_truename_len)
+ __v = 1;
+ else
+ __err |= ios_base::failbit;
+
if (__beg == __end)
__err |= ios_base::eofbit;
}
return __beg;
}
-#endif
template<typename _CharT, typename _InIter>
_InIter
num_get<_CharT, _InIter>::
do_get(iter_type __beg, iter_type __end, ios_base& __io,
ios_base::iostate& __err, long& __v) const
- {
- string __xtrc;
- int __base;
- __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base);
- __convert_to_v(__xtrc.c_str(), __v, __err, _S_c_locale, __base);
- return __beg;
- }
+ { return _M_extract_int(__beg, __end, __io, __err, __v); }
template<typename _CharT, typename _InIter>
_InIter
num_get<_CharT, _InIter>::
do_get(iter_type __beg, iter_type __end, ios_base& __io,
ios_base::iostate& __err, unsigned short& __v) const
- {
- string __xtrc;
- int __base;
- __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base);
- unsigned long __ul;
- __convert_to_v(__xtrc.c_str(), __ul, __err, _S_c_locale, __base);
- if (!(__err & ios_base::failbit)
- && __ul <= numeric_limits<unsigned short>::max())
- __v = static_cast<unsigned short>(__ul);
- else
- __err |= ios_base::failbit;
- return __beg;
- }
+ { return _M_extract_int(__beg, __end, __io, __err, __v); }
template<typename _CharT, typename _InIter>
_InIter
num_get<_CharT, _InIter>::
do_get(iter_type __beg, iter_type __end, ios_base& __io,
ios_base::iostate& __err, unsigned int& __v) const
- {
- string __xtrc;
- int __base;
- __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base);
- unsigned long __ul;
- __convert_to_v(__xtrc.c_str(), __ul, __err, _S_c_locale, __base);
- if (!(__err & ios_base::failbit)
- && __ul <= numeric_limits<unsigned int>::max())
- __v = static_cast<unsigned int>(__ul);
- else
- __err |= ios_base::failbit;
- return __beg;
- }
+ { return _M_extract_int(__beg, __end, __io, __err, __v); }
template<typename _CharT, typename _InIter>
_InIter
num_get<_CharT, _InIter>::
do_get(iter_type __beg, iter_type __end, ios_base& __io,
ios_base::iostate& __err, unsigned long& __v) const
- {
- string __xtrc;
- int __base;
- __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base);
- __convert_to_v(__xtrc.c_str(), __v, __err, _S_c_locale, __base);
- return __beg;
- }
+ { return _M_extract_int(__beg, __end, __io, __err, __v); }
-#ifdef _GLIBCPP_USE_LONG_LONG
+#ifdef _GLIBCXX_USE_LONG_LONG
template<typename _CharT, typename _InIter>
_InIter
num_get<_CharT, _InIter>::
do_get(iter_type __beg, iter_type __end, ios_base& __io,
ios_base::iostate& __err, long long& __v) const
- {
- string __xtrc;
- int __base;
- __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base);
- __convert_to_v(__xtrc.c_str(), __v, __err, _S_c_locale, __base);
- return __beg;
- }
+ { return _M_extract_int(__beg, __end, __io, __err, __v); }
template<typename _CharT, typename _InIter>
_InIter
num_get<_CharT, _InIter>::
do_get(iter_type __beg, iter_type __end, ios_base& __io,
ios_base::iostate& __err, unsigned long long& __v) const
- {
- string __xtrc;
- int __base;
- __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base);
- __convert_to_v(__xtrc.c_str(), __v, __err, _S_c_locale, __base);
- return __beg;
- }
+ { return _M_extract_int(__beg, __end, __io, __err, __v); }
#endif
template<typename _CharT, typename _InIter>
string __xtrc;
__xtrc.reserve(32);
__beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
- __convert_to_v(__xtrc.c_str(), __v, __err, _S_c_locale);
+ std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
return __beg;
}
string __xtrc;
__xtrc.reserve(32);
__beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
- __convert_to_v(__xtrc.c_str(), __v, __err, _S_c_locale);
+ std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
return __beg;
}
string __xtrc;
__xtrc.reserve(32);
__beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
- __convert_to_v(__xtrc.c_str(), __v, __err, _S_c_locale);
+ std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
return __beg;
}
do_get(iter_type __beg, iter_type __end, ios_base& __io,
ios_base::iostate& __err, void*& __v) const
{
- // Prepare for hex formatted input
+ // Prepare for hex formatted input.
typedef ios_base::fmtflags fmtflags;
- fmtflags __fmt = __io.flags();
- fmtflags __fmtmask = ~(ios_base::showpos | ios_base::basefield
- | ios_base::uppercase | ios_base::internal);
- __io.flags(__fmt & __fmtmask | (ios_base::hex | ios_base::showbase));
+ const fmtflags __fmt = __io.flags();
+ __io.flags(__fmt & ~ios_base::basefield | ios_base::hex);
- string __xtrc;
- int __base;
- __beg = _M_extract_int(__beg, __end, __io, __err, __xtrc, __base);
+ unsigned long __ul;
+ __beg = _M_extract_int(__beg, __end, __io, __err, __ul);
- // Reset from hex formatted input
+ // Reset from hex formatted input.
__io.flags(__fmt);
- unsigned long __ul;
- __convert_to_v(__xtrc.c_str(), __ul, __err, _S_c_locale, __base);
if (!(__err & ios_base::failbit))
__v = reinterpret_cast<void*>(__ul);
else
return __beg;
}
- // The following code uses snprintf (or sprintf(), when _GLIBCPP_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]
+ // 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;
+ }
+
template<typename _CharT, typename _OutIter>
template<typename _ValueT>
_OutIter
num_put<_CharT, _OutIter>::
- _M_convert_float(_OutIter __s, ios_base& __io, _CharT __fill, char __mod,
- _ValueT __v) const
+ _M_insert_int(_OutIter __s, ios_base& __io, _CharT __fill,
+ _ValueT __v) const
{
- // Note: digits10 is rounded down. We need to add 1 to ensure
- // we get the full available precision.
- const int __max_digits = numeric_limits<_ValueT>::digits10 + 1;
- streamsize __prec = __io.precision();
-
- if (__prec > static_cast<streamsize>(__max_digits))
- __prec = static_cast<streamsize>(__max_digits);
+ typedef typename numpunct<_CharT>::__cache_type __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;
- // Long enough for the max format spec.
- char __fbuf[16];
+ // Long enough to hold hex, dec, and octal representations.
+ const int __ilen = 4 * 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;
-#ifdef _GLIBCPP_USE_C99
- // First try a buffer perhaps big enough (for sure sufficient for
- // non-ios_base::fixed outputs)
- int __cs_size = __max_digits * 3;
- char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
-
- const bool __fp = _S_format_float(__io, __fbuf, __mod, __prec);
- if (__fp)
- __len = __convert_from_v(__cs, __cs_size, __fbuf, __v,
- _S_c_locale, __prec);
- else
- __len = __convert_from_v(__cs, __cs_size, __fbuf, __v, _S_c_locale);
-
- // If the buffer was not large enough, try again with the correct size.
- if (__len >= __cs_size)
+ __len = __int_to_char(__cs + __ilen, __v, __lit, __io.flags());
+ __cs += __ilen - __len;
+
+ // Add grouping, if necessary.
+ if (__lc->_M_use_grouping)
{
- __cs_size = __len + 1;
- __cs = static_cast<char*>(__builtin_alloca(__cs_size));
- if (__fp)
- __len = __convert_from_v(__cs, __cs_size, __fbuf, __v,
- _S_c_locale, __prec);
- else
- __len = __convert_from_v(__cs, __cs_size, __fbuf, __v,
- _S_c_locale);
+ // Grouping can add (almost) as many separators as the
+ // number of digits, but no more.
+ _CharT* __cs2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
+ * __len * 2));
+ _M_group_int(__lc->_M_grouping, __lc->_M_thousands_sep, __io,
+ __cs2, __cs, __len);
+ __cs = __cs2;
}
-#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;
- // ios_base::fixed outputs may need up to __max_exp+1 chars
- // for the integer part + up to __max_digits chars for the
- // fractional part + 3 chars for sign, decimal point, '\0'. On
- // the other hand, for non-fixed outputs __max_digits*3 chars
- // are largely sufficient.
- const int __cs_size = __fixed ? __max_exp + __max_digits + 4
- : __max_digits * 3;
- char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
+
+ // 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);
- if (_S_format_float(__io, __fbuf, __mod, __prec))
- __len = __convert_from_v(__cs, 0, __fbuf, __v, _S_c_locale, __prec);
- else
- __len = __convert_from_v(__cs, 0, __fbuf, __v, _S_c_locale);
-#endif
- return _M_widen_float(__s, __io, __fill, __cs, __len);
- }
+ // [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 string& __grouping, _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.
+ _CharT* __p2;
+ const int __declen = __p ? __p - __cs : __len;
+ __p2 = std::__add_grouping(__new, __sep, __grouping.data(),
+ __grouping.data() + __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_convert_int(_OutIter __s, ios_base& __io, _CharT __fill, char __mod,
- char __modl, _ValueT __v) const
+ _M_insert_float(_OutIter __s, ios_base& __io, _CharT __fill, char __mod,
+ _ValueT __v) const
{
- // [22.2.2.2.2] Stage 1, numeric conversion to character.
+ typedef typename numpunct<_CharT>::__cache_type __cache_type;
+ __use_cache<__cache_type> __uc;
+ const locale& __loc = __io._M_getloc();
+ const __cache_type* __lc = __uc(__loc);
+
+ // Note: digits10 is rounded down: add 1 to ensure the maximum
+ // available precision. Then, in general, one more 1 needs to
+ // be added since, when the %{g,G} conversion specifiers are
+ // chosen inside _S_format_float, the precision field is "the
+ // maximum number of significant digits", *not* the "number of
+ // digits to appear after the decimal point", as happens for
+ // %{e,E,f,F} (C99, 7.19.6.1,4).
+ const int __max_digits = numeric_limits<_ValueT>::digits10 + 2;
+
+ // Use default precision if out of range.
+ streamsize __prec = __io.precision();
+ if (__prec > static_cast<streamsize>(__max_digits))
+ __prec = static_cast<streamsize>(__max_digits);
+ else if (__prec < static_cast<streamsize>(0))
+ __prec = static_cast<streamsize>(6);
+ // [22.2.2.2.2] Stage 1, numeric conversion to character.
+ int __len;
// Long enough for the max format spec.
char __fbuf[16];
- _S_format_int(__io, __fbuf, __mod, __modl);
-#ifdef _GLIBCPP_USE_C99
- // First try a buffer perhaps big enough.
- int __cs_size = 64;
+
+#ifdef _GLIBCXX_USE_C99
+ // First try a buffer perhaps big enough (for sure sufficient
+ // for non-ios_base::fixed outputs)
+ int __cs_size = __max_digits * 3;
char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
- int __len = __convert_from_v(__cs, __cs_size, __fbuf, __v,
- _S_c_locale);
+
+ _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_size = __len + 1;
__cs = static_cast<char*>(__builtin_alloca(__cs_size));
- __len = __convert_from_v(__cs, __cs_size, __fbuf, __v,
- _S_c_locale);
+ __len = std::__convert_from_v(__cs, __cs_size, __fbuf, __v,
+ _S_get_c_locale(), __prec);
}
#else
- // Leave room for "+/-," "0x," and commas. This size is
- // arbitrary, but should be largely sufficient.
- char __cs[128];
- int __len = __convert_from_v(__cs, 0, __fbuf, __v, _S_c_locale);
+ // 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 + up to __max_digits chars for the
+ // fractional part + 3 chars for sign, decimal point, '\0'. On
+ // the other hand, for non-fixed outputs __max_digits*3 chars
+ // are largely sufficient.
+ const int __cs_size = __fixed ? __max_exp + __max_digits + 4
+ : __max_digits * 3;
+ char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
+
+ _S_format_float(__io, __fbuf, __mod);
+ __len = std::__convert_from_v(__cs, 0, __fbuf, __v,
+ _S_get_c_locale(), __prec);
#endif
- return _M_widen_int(__s, __io, __fill, __cs, __len);
- }
- template<typename _CharT, typename _OutIter>
- _OutIter
- num_put<_CharT, _OutIter>::
- _M_widen_float(_OutIter __s, ios_base& __io, _CharT __fill, char* __cs,
- int __len) const
- {
- typedef char_traits<_CharT> __traits_type;
// [22.2.2.2.2] Stage 2, convert to char_type, using correct
// numpunct.decimal_point() values for '.' and adding grouping.
- const locale __loc = __io.getloc();
const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
+
_CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
* __len));
- // 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));
__ctype.widen(__cs, __cs + __len, __ws);
// Replace decimal point.
+ const _CharT __cdec = __ctype.widen('.');
+ const _CharT __dec = __lc->_M_decimal_point;
const _CharT* __p;
- const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
- if (__p = __traits_type::find(__ws, __len, __ctype.widen('.')))
- __ws[__p - __ws] = __np.decimal_point();
-
-#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
-//282. What types does numpunct grouping refer to?
- // Add grouping, if necessary.
- const string __grouping = __np.grouping();
- ios_base::fmtflags __basefield = __io.flags() & ios_base::basefield;
- if (__grouping.size())
- {
- _CharT* __p2;
- int __declen = __p ? __p - __ws : __len;
- __p2 = __add_grouping(__ws2, __np.thousands_sep(),
- __grouping.c_str(),
- __grouping.c_str() + __grouping.size(),
- __ws, __ws + __declen);
- int __newlen = __p2 - __ws2;
-
- // Tack on decimal part.
- if (__p)
- {
- __traits_type::copy(__p2, __p, __len - __declen);
- __newlen += __len - __declen;
- }
-
- // Switch strings, establish correct new length.
- __ws = __ws2;
- __len = __newlen;
- }
-#endif
- return _M_insert(__s, __io, __fill, __ws, __len);
- }
-
- template<typename _CharT, typename _OutIter>
- _OutIter
- num_put<_CharT, _OutIter>::
- _M_widen_int(_OutIter __s, ios_base& __io, _CharT __fill, char* __cs,
- int __len) const
- {
- // [22.2.2.2.2] Stage 2, convert to char_type, using correct
- // numpunct.decimal_point() values for '.' and adding grouping.
- const locale __loc = __io.getloc();
- const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
- _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
- * __len));
- // 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));
- __ctype.widen(__cs, __cs + __len, __ws);
+ if (__p = char_traits<_CharT>::find(__ws, __len, __cdec))
+ __ws[__p - __ws] = __dec;
// Add grouping, if necessary.
- const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
- const string __grouping = __np.grouping();
- const ios_base::fmtflags __basefield = __io.flags() & ios_base::basefield;
- if (__grouping.size())
+ if (__lc->_M_use_grouping)
{
- // By itself __add_grouping cannot deal correctly with __ws 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;
- if ((__io.flags() & ios_base::showbase) && __len > 1)
- if (__basefield == ios_base::oct)
- {
- __off = 1;
- *__ws2 = *__ws;
- }
- else if (__basefield == ios_base::hex)
- {
- __off = 2;
- *__ws2 = *__ws;
- *(__ws2 + 1) = *(__ws + 1);
- }
- _CharT* __p;
- __p = __add_grouping(__ws2 + __off, __np.thousands_sep(),
- __grouping.c_str(),
- __grouping.c_str() + __grouping.size(),
- __ws + __off, __ws + __len);
- __len = __p - __ws2;
- // Switch strings.
+ // 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));
+ _M_group_float(__lc->_M_grouping, __lc->_M_thousands_sep, __p,
+ __ws2, __ws, __len);
__ws = __ws2;
}
- return _M_insert(__s, __io, __fill, __ws, __len);
- }
- // For use by integer and floating-point types after they have been
- // converted into a char_type string.
- template<typename _CharT, typename _OutIter>
- _OutIter
- num_put<_CharT, _OutIter>::
- _M_insert(_OutIter __s, ios_base& __io, _CharT __fill, const _CharT* __ws,
- int __len) const
- {
- typedef char_traits<_CharT> __traits_type;
- // [22.2.2.2.2] Stage 3.
- streamsize __w = __io.width();
- _CharT* __ws2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
- * __w));
+ // Pad.
+ const streamsize __w = __io.width();
if (__w > static_cast<streamsize>(__len))
{
- __pad<_CharT, __traits_type>::_S_pad(__io, __fill, __ws2, __ws,
- __w, __len, true);
- __len = static_cast<int>(__w);
- // Switch strings.
- __ws = __ws2;
+ _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.
- for (int __j = 0; __j < __len; ++__j, ++__s)
- *__s = __ws[__j];
- return __s;
- }
+ 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
{
- ios_base::fmtflags __flags = __io.flags();
+ const ios_base::fmtflags __flags = __io.flags();
if ((__flags & ios_base::boolalpha) == 0)
{
unsigned long __uv = __v;
- __s = _M_convert_int(__s, __io, __fill, 'u', char(), __uv);
+ __s = _M_insert_int(__s, __io, __fill, __uv);
}
else
{
- typedef basic_string<_CharT> __string_type;
- locale __loc = __io.getloc();
- const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
- __string_type __name;
- if (__v)
- __name = __np.truename();
- else
- __name = __np.falsename();
- __s = _M_insert(__s, __io, __fill, __name.c_str(), __name.size());
+ typedef typename numpunct<_CharT>::__cache_type __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_len
+ : __lc->_M_falsename_len;
+
+ 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;
}
_OutIter
num_put<_CharT, _OutIter>::
do_put(iter_type __s, ios_base& __io, char_type __fill, long __v) const
- { return _M_convert_int(__s, __io, __fill, 'd', char(), __v); }
+ { 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_convert_int(__s, __io, __fill, 'u', char(), __v); }
+ { return _M_insert_int(__s, __io, __fill, __v); }
-#ifdef _GLIBCPP_USE_LONG_LONG
+#ifdef _GLIBCXX_USE_LONG_LONG
template<typename _CharT, typename _OutIter>
_OutIter
num_put<_CharT, _OutIter>::
do_put(iter_type __s, ios_base& __b, char_type __fill, long long __v) const
- { return _M_convert_int(__s, __b, __fill, 'd', 'l', __v); }
+ { return _M_insert_int(__s, __b, __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_convert_int(__s, __io, __fill, 'u', 'l', __v); }
+ { 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_convert_float(__s, __io, __fill, char(), __v); }
+ { 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_convert_float(__s, __io, __fill, 'L', __v); }
+ { return _M_insert_float(__s, __io, __fill, 'L', __v); }
template<typename _CharT, typename _OutIter>
_OutIter
do_put(iter_type __s, ios_base& __io, char_type __fill,
const void* __v) const
{
- ios_base::fmtflags __flags = __io.flags();
- ios_base::fmtflags __fmt = ~(ios_base::showpos | ios_base::basefield
- | ios_base::uppercase | ios_base::internal);
+ const ios_base::fmtflags __flags = __io.flags();
+ const ios_base::fmtflags __fmt = ~(ios_base::showpos | ios_base::basefield
+ | ios_base::uppercase | ios_base::internal);
__io.flags(__flags & __fmt | (ios_base::hex | ios_base::showbase));
- try
- {
- __s = _M_convert_int(__s, __io, __fill, 'u', char(),
- reinterpret_cast<unsigned long>(__v));
- __io.flags(__flags);
- }
- catch (...)
- {
- __io.flags(__flags);
- __throw_exception_again;
- }
+
+ __s = _M_insert_int(__s, __io, __fill,
+ reinterpret_cast<unsigned long>(__v));
+ __io.flags(__flags);
return __s;
}
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 int __cs_size = __str.size() + 1;
+ char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
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);
+ __ctype.narrow(__wcs, __wcs + __cs_size, char(), __cs);
+ std::__convert_to_v(__cs, __units, __err, _S_get_c_locale());
return __beg;
}
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 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()
bool __testdecfound = false;
// The tentative returned string is stored here.
- string_type __temp_units;
+ string_type __tmp_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]);
+ char_type __c;
+ const 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))
{
- 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())
+ // 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();
+ const size_type __len = __symbol.size();
+ size_type __j = 0;
+ for (; __beg != __end && __j < __len
+ && *__beg == __symbol[__j]; ++__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() && *__beg == __pos_sign[0])
+ {
+ __sign = __pos_sign;
+ ++__beg;
+ }
+ else if (__neg_sign.size() && *__beg == __neg_sign[0])
+ {
+ __sign = __neg_sign;
+ ++__beg;
+ }
+ else if (__pos_sign.size() && __neg_sign.size())
+ {
+ // Sign is mandatory.
+ __testvalid = false;
+ }
+ break;
+ case money_base::value:
+ // Extract digits, remove and stash away the
+ // grouping of found thousands separators.
+ for (; __beg != __end; ++__beg)
+ if (__ctype.is(ctype_base::digit, __c = *__beg))
{
- // Sign is mandatory.
- if (__c == __pos_sign[0])
+ __tmp_units += __c;
+ ++__sep_pos;
+ }
+ else if (__c == __d && !__testdecfound)
+ {
+ __grouping_tmp += static_cast<char>(__sep_pos);
+ __sep_pos = 0;
+ __testdecfound = true;
+ }
+ else if (__c == __sep)
+ {
+ if (__grouping.size())
{
- __sign = __pos_sign;
- __c = *(++__beg);
+ // Mark position for later analysis.
+ __grouping_tmp += static_cast<char>(__sep_pos);
+ __sep_pos = 0;
}
- else if (__c == __neg_sign[0])
+ else
{
- __sign = __neg_sign;
- __c = *(++__beg);
+ __testvalid = false;
+ break;
}
- 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);
+ else
break;
- }
+ break;
+ case money_base::space:
+ case money_base::none:
+ // Only if not at the end of the pattern.
+ if (__i != 3)
+ for (; __beg != __end
+ && __ctype.is(ctype_base::space, *__beg); ++__beg);
+ break;
+ }
}
-
+
// Need to get the rest of the sign characters, if they exist.
if (__sign.size() > 1)
{
- size_type __len = __sign.size();
+ const size_type __len = __sign.size();
size_type __i = 1;
- for (; __c != __eof && __i < __len; ++__i)
- while (__beg != __end && __c != __sign[__i])
- __c = *(++__beg);
+ for (; __beg != __end && __i < __len; ++__i)
+ for (; __beg != __end
+ && *__beg != __sign[__i]; ++__beg);
if (__i != __len)
__testvalid = false;
}
- // Strip leading zeros.
- while (__temp_units[0] == __ctype.widen('0'))
- __temp_units.erase(__temp_units.begin());
+ if (__testvalid && __tmp_units.size())
+ {
+ const char_type __zero = __ctype.widen('0');
- if (__sign.size() && __sign == __neg_sign)
- __temp_units.insert(__temp_units.begin(), __ctype.widen('-'));
+ // Strip leading zeros.
+ if (__tmp_units.size() > 1)
+ {
+ const size_type __first = __tmp_units.find_first_not_of(__zero);
+ const bool __only_zeros = __first == string_type::npos;
+ if (__first)
+ __tmp_units.erase(0, __only_zeros ? __tmp_units.size() - 1
+ : __first);
+ }
+
+ // 22.2.6.1.2, p4
+ if (__sign.size() && __sign == __neg_sign
+ && __tmp_units[0] != __zero)
+ __tmp_units.insert(__tmp_units.begin(), __ctype.widen('-'));
- // Test for grouping fidelity.
- if (__grouping.size() && __grouping_tmp.size())
- {
- if (!__verify_grouping(__grouping, __grouping_tmp))
- __testvalid = false;
+ // Test for grouping fidelity.
+ if (__grouping.size() && __grouping_tmp.size())
+ {
+ if (!std::__verify_grouping(__grouping, __grouping_tmp))
+ __testvalid = false;
+ }
+
+ // Iff not enough digits were supplied after the decimal-point.
+ if (__testdecfound)
+ {
+ const int __frac = __intl ? __mpt.frac_digits()
+ : __mpf.frac_digits();
+ if (__frac > 0 && __sep_pos != __frac)
+ __testvalid = false;
+ }
}
+ else
+ __testvalid = false;
// Iff no more characters are available.
- if (__c == __eof)
+ if (__beg == __end)
__err |= ios_base::eofbit;
// Iff valid sequence is not recognized.
- if (!__testvalid || !__temp_units.size())
+ if (!__testvalid)
__err |= ios_base::failbit;
else
- // Use the "swap trick" to copy __temp_units into __units.
- __temp_units.swap(__units);
+ // Use the "swap trick" to copy __tmp_units into __units.
+ __tmp_units.swap(__units);
return __beg;
}
{
const locale __loc = __io.getloc();
const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
-#ifdef _GLIBCPP_USE_C99
+#ifdef _GLIBCXX_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);
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 328. Bad sprintf format modifier in money_put<>::do_put()
+ int __len = std::__convert_from_v(__cs, __cs_size, "%.0Lf", __units,
+ _S_get_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);
+ __len = std::__convert_from_v(__cs, __cs_size, "%.0Lf", __units,
+ _S_get_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;
+ // max_exponent10 + 1 for the integer part, + 2 for sign and '\0'.
+ const int __cs_size = numeric_limits<long double>::max_exponent10 + 3;
char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
- int __len = __convert_from_v(__cs, 0, "%.01Lf", __units, _S_c_locale);
+ int __len = std::__convert_from_v(__cs, 0, "%.0Lf", __units,
+ _S_get_c_locale());
#endif
- _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __cs_size));
+ _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);
if (*__beg != __ctype.widen('-'))
{
__p = __intl ? __mpt.pos_format() : __mpf.pos_format();
- __sign =__intl ? __mpt.positive_sign() : __mpf.positive_sign();
+ __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();
+ __sign = __intl ? __mpt.negative_sign() : __mpf.negative_sign();
++__beg;
}
{
// Have to pad zeros in the decimal position.
__value = string_type(__beg, __end);
- int __paddec = __frac - (__end - __beg);
- char_type __zero = __ctype.widen('0');
+ const int __paddec = __frac - (__end - __beg);
+ const char_type __zero = __ctype.widen('0');
__value.insert(__value.begin(), __paddec, __zero);
__value.insert(__value.begin(), __d);
__beg = __end;
{
const char_type __sep = __intl ? __mpt.thousands_sep()
: __mpf.thousands_sep();
- const char* __gbeg = __grouping.c_str();
+ const char* __gbeg = __grouping.data();
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);
+ static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __n));
+ _CharT* __ws_end = std::__add_grouping(__ws2, __sep, __gbeg,
+ __gend, __beg, __end);
__value.insert(0, __ws2, __ws_end - __ws2);
}
else
}
// Calculate length of resulting string.
- ios_base::fmtflags __f = __io.flags() & ios_base::adjustfield;
+ const 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;
+ const 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]);
+ const part __which = static_cast<part>(__p.field[__i]);
switch (__which)
{
case money_base::symbol:
}
// Write resulting, fully-formatted string to output iterator.
- for (size_type __j = 0; __j < __len; ++__j, ++__s)
- *__s = __res[__j];
+ __s = std::__write(__s, __res.data(), __len);
}
__io.width(0);
return __s;
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>::
ios_base::iostate& __err, tm* __tm,
const _CharT* __format) const
{
- locale __loc = __io.getloc();
- __timepunct<_CharT> const& __tp = use_facet<__timepunct<_CharT> >(__loc);
+ const locale __loc = __io.getloc();
+ const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
- size_t __len = char_traits<_CharT>::length(__format);
+ const size_t __len = char_traits<_CharT>::length(__format);
for (size_t __i = 0; __beg != __end && __i < __len && !__err; ++__i)
{
- char __c = __format[__i];
- if (__c == '%')
+ if (__ctype.narrow(__format[__i], 0) == '%')
{
// Verify valid formatting code, attempt to extract.
- __c = __format[++__i];
- char __mod = 0;
+ char __c = __ctype.narrow(__format[++__i], 0);
int __mem = 0;
if (__c == 'E' || __c == 'O')
- {
- __mod = __c;
- __c = __format[++__i];
- }
+ __c = __ctype.narrow(__format[++__i], 0);
switch (__c)
{
const char* __cs;
const char_type* __days1[7];
__tp._M_days_abbreviated(__days1);
_M_extract_name(__beg, __end, __tm->tm_wday, __days1, 7,
- __err);
+ __ctype, __err);
break;
case 'A':
// Weekday name [tm_wday].
const char_type* __days2[7];
__tp._M_days(__days2);
_M_extract_name(__beg, __end, __tm->tm_wday, __days2, 7,
- __err);
+ __ctype, __err);
break;
case 'h':
case 'b':
const char_type* __months1[12];
__tp._M_months_abbreviated(__months1);
_M_extract_name(__beg, __end, __tm->tm_mon, __months1, 12,
- __err);
+ __ctype, __err);
break;
case 'B':
// Month name [tm_mon].
const char_type* __months2[12];
__tp._M_months(__months2);
_M_extract_name(__beg, __end, __tm->tm_mon, __months2, 12,
- __err);
+ __ctype, __err);
break;
case 'c':
// Default time and date representation.
_M_extract_num(__beg, __end, __tm->tm_mday, 1, 31, 2,
__ctype, __err);
break;
+ case 'e':
+ // Day [1, 31], with single digits preceded by
+ // space. [tm_mday]
+ if (__ctype.is(ctype_base::space, *__beg))
+ _M_extract_num(++__beg, __end, __tm->tm_mday, 1, 9, 1,
+ __ctype, __err);
+ else
+ _M_extract_num(__beg, __end, __tm->tm_mday, 10, 31, 2,
+ __ctype, __err);
+ break;
case 'D':
// Equivalent to %m/%d/%y.[tm_mon, tm_mday, tm_year]
__cs = "%m/%d/%y";
if (__ctype.narrow(*__beg, 0) == '\t')
++__beg;
else
- __err |= ios_base::failbit;
+ __err |= ios_base::failbit;
break;
case 'T':
// Equivalent to (%H:%M:%S).
__times[0]);
break;
case 'y':
+ case 'C': // C99
// Two digit year. [tm_year]
_M_extract_num(__beg, __end, __tm->tm_year, 0, 99, 2,
__ctype, __err);
break;
case 'Y':
// Year [1900). [tm_year]
- _M_extract_num(__beg, __end, __mem, 0,
- numeric_limits<int>::max(), 4,
+ _M_extract_num(__beg, __end, __mem, 0, 9999, 4,
__ctype, __err);
if (!__err)
__tm->tm_year = __mem - 1900;
{
int __tmp;
_M_extract_name(__beg, __end, __tmp,
- __timepunct<_CharT>::_S_timezones,
- 14, __err);
+ __timepunct_cache<_CharT>::_S_timezones,
+ 14, __ctype, __err);
// GMT requires special effort.
- char_type __c = *__beg;
- if (!__err && __tmp == 0
- && (__c == __ctype.widen('-')
- || __c == __ctype.widen('+')))
+ if (__beg != __end && !__err && __tmp == 0
+ && (*__beg == __ctype.widen('-')
+ || *__beg == __ctype.widen('+')))
{
_M_extract_num(__beg, __end, __tmp, 0, 23, 2,
__ctype, __err);
_M_extract_num(__beg, __end, __tmp, 0, 59, 2,
__ctype, __err);
}
- }
- else
- __err |= ios_base::failbit;
- break;
- default:
- // Not recognized.
- __err |= ios_base::failbit;
}
- }
- else
- {
- // Verify format and input match, extract and discard.
- if (__c == __ctype.narrow(*__beg, 0))
- ++__beg;
else
__err |= ios_base::failbit;
+ break;
+ default:
+ // Not recognized.
+ __err |= ios_base::failbit;
}
+ }
+ else
+ {
+ // Verify format and input match, extract and discard.
+ if (__format[__i] == *__beg)
+ ++__beg;
+ else
+ __err |= ios_base::failbit;
+ }
}
}
const ctype<_CharT>& __ctype,
ios_base::iostate& __err) const
{
+ // As-is works for __len = 1, 2, 4, the values actually used.
+ int __mult = __len == 2 ? 10 : (__len == 4 ? 1000 : 1);
+
+ ++__min;
size_t __i = 0;
- string __digits;
- bool __testvalid = true;
- char_type __c = *__beg;
- while (__beg != __end && __i < __len
- && __ctype.is(ctype_base::digit, __c))
- {
- __digits += __ctype.narrow(__c, 0);
- __c = *(++__beg);
- ++__i;
- }
- if (__i == __len)
+ int __value = 0;
+ for (; __beg != __end && __i < __len; ++__beg, ++__i)
{
- int __value = atoi(__digits.c_str());
- if (__min <= __value && __value <= __max)
- __member = __value;
+ const char __c = __ctype.narrow(*__beg, '*');
+ if (__c >= '0' && __c <= '9')
+ {
+ __value = __value * 10 + (__c - '0');
+ const int __valuec = __value * __mult;
+ if (__valuec > __max || __valuec + __mult < __min)
+ break;
+ __mult /= 10;
+ }
else
- __testvalid = false;
+ break;
}
+ if (__i == __len)
+ __member = __value;
else
- __testvalid = false;
- if (!__testvalid)
__err |= ios_base::failbit;
}
time_get<_CharT, _InIter>::
_M_extract_name(iter_type& __beg, iter_type& __end, int& __member,
const _CharT** __names, size_t __indexlen,
+ const ctype<_CharT>& __ctype,
ios_base::iostate& __err) const
{
typedef char_traits<_CharT> __traits_type;
- int* __matches = static_cast<int*>(__builtin_alloca(sizeof(int) * __indexlen));
+ int* __matches = static_cast<int*>(__builtin_alloca(sizeof(int)
+ * __indexlen));
size_t __nmatches = 0;
size_t __pos = 0;
bool __testvalid = true;
const char_type* __name;
- char_type __c = *__beg;
- // Look for initial matches.
- for (size_t __i1 = 0; __i1 < __indexlen; ++__i1)
- if (__c == __names[__i1][0])
- __matches[__nmatches++] = __i1;
+ // Look for initial matches.
+ // NB: Some of the locale data is in the form of all lowercase
+ // names, and some is in the form of initially-capitalized
+ // names. Look for both.
+ if (__beg != __end)
+ {
+ const char_type __c = *__beg;
+ for (size_t __i1 = 0; __i1 < __indexlen; ++__i1)
+ if (__c == __names[__i1][0]
+ || __c == __ctype.toupper(__names[__i1][0]))
+ __matches[__nmatches++] = __i1;
+ }
- while(__nmatches > 1)
+ while (__nmatches > 1)
{
// Find smallest matching string.
size_t __minlen = 10;
for (size_t __i2 = 0; __i2 < __nmatches; ++__i2)
__minlen = std::min(__minlen,
__traits_type::length(__names[__matches[__i2]]));
-
+ ++__beg;
if (__pos < __minlen && __beg != __end)
{
++__pos;
- __c = *(++__beg);
for (size_t __i3 = 0; __i3 < __nmatches; ++__i3)
{
__name = __names[__matches[__i3]];
- if (__name[__pos] != __c)
+ if (__name[__pos] != *__beg)
__matches[__i3] = __matches[--__nmatches];
}
}
if (__nmatches == 1)
{
+ // If there was only one match, the first compare is redundant.
+ if (__pos == 0)
+ {
+ ++__pos;
+ ++__beg;
+ }
+
// Make sure found name is completely extracted.
__name = __names[__matches[0]];
const size_t __len = __traits_type::length(__name);
{
_CharT __wcs[3];
const char* __cs = "%X";
- locale __loc = __io.getloc();
+ const locale __loc = __io.getloc();
ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
__ctype.widen(__cs, __cs + 3, __wcs);
_M_extract_via_format(__beg, __end, __io, __err, __tm, __wcs);
{
_CharT __wcs[3];
const char* __cs = "%x";
- locale __loc = __io.getloc();
+ const locale __loc = __io.getloc();
ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
__ctype.widen(__cs, __cs + 3, __wcs);
_M_extract_via_format(__beg, __end, __io, __err, __tm, __wcs);
ios_base::iostate& __err, tm* __tm) const
{
typedef char_traits<_CharT> __traits_type;
- locale __loc = __io.getloc();
- __timepunct<_CharT> const& __tp = use_facet<__timepunct<_CharT> >(__loc);
+ const locale __loc = __io.getloc();
+ const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
+ const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
const char_type* __days[7];
__tp._M_days_abbreviated(__days);
int __tmpwday;
- _M_extract_name(__beg, __end, __tmpwday, __days, 7, __err);
+ _M_extract_name(__beg, __end, __tmpwday, __days, 7, __ctype, __err);
// Check to see if non-abbreviated name exists, and extract.
// NB: Assumes both _M_days and _M_days_abbreviated organized in
ios_base& __io, ios_base::iostate& __err, tm* __tm) const
{
typedef char_traits<_CharT> __traits_type;
- locale __loc = __io.getloc();
- __timepunct<_CharT> const& __tp = use_facet<__timepunct<_CharT> >(__loc);
+ const locale __loc = __io.getloc();
+ const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
+ const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
const char_type* __months[12];
__tp._M_months_abbreviated(__months);
int __tmpmon;
- _M_extract_name(__beg, __end, __tmpmon, __months, 12, __err);
+ _M_extract_name(__beg, __end, __tmpmon, __months, 12, __ctype, __err);
// Check to see if non-abbreviated name exists, and extract.
// NB: Assumes both _M_months and _M_months_abbreviated organized in
do_get_year(iter_type __beg, iter_type __end, ios_base& __io,
ios_base::iostate& __err, tm* __tm) const
{
- locale __loc = __io.getloc();
+ const locale __loc = __io.getloc();
const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
- char_type __c = *__beg;
size_t __i = 0;
- string __digits;
- while (__i < 4 && __beg != __end && __ctype.is(ctype_base::digit, __c))
+ int __value = 0;
+ for (; __beg != __end && __i < 4; ++__beg, ++__i)
{
- __digits += __ctype.narrow(__c, 0);
- __c = *(++__beg);
- ++__i;
+ const char __c = __ctype.narrow(*__beg, '*');
+ if (__c >= '0' && __c <= '9')
+ __value = __value * 10 + (__c - '0');
+ else
+ break;
}
if (__i == 2 || __i == 4)
- {
- long __l;
- __convert_to_v(__digits.c_str(), __l, __err, _S_c_locale);
- if (!(__err & ios_base::failbit) && __l <= INT_MAX)
- {
- __l = __i == 2 ? __l : __l - 1900;
- __tm->tm_year = static_cast<int>(__l);
- }
- }
+ __tm->tm_year = __i == 2 ? __value : __value - 1900;
else
__err |= ios_base::failbit;
if (__beg == __end)
template<typename _CharT, typename _OutIter>
_OutIter
time_put<_CharT, _OutIter>::
- put(iter_type __s, ios_base& __io, char_type, const tm* __tm,
+ put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
const _CharT* __beg, const _CharT* __end) const
{
- locale __loc = __io.getloc();
+ const locale __loc = __io.getloc();
ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
- while (__beg != __end)
- {
- char __c = __ctype.narrow(*__beg, 0);
- ++__beg;
- if (__c == '%')
- {
- char __format;
- char __mod = 0;
- size_t __len = 1;
- __c = __ctype.narrow(*__beg, 0);
- ++__beg;
- if (__c == 'E' || __c == 'O')
- {
- __mod = __c;
- __format = __ctype.narrow(*__beg, 0);
- ++__beg;
- }
- else
- __format = __c;
- __s = this->do_put(__s, __io, char_type(), __tm, __format,
- __mod);
- }
- else
- {
- *__s = __c;
- ++__s;
- }
- }
+ for (; __beg != __end; ++__beg)
+ if (__ctype.narrow(*__beg, 0) != '%')
+ {
+ *__s = *__beg;
+ ++__s;
+ }
+ else if (++__beg != __end)
+ {
+ char __format;
+ char __mod = 0;
+ const char __c = __ctype.narrow(*__beg, 0);
+ if (__c != 'E' && __c != 'O')
+ __format = __c;
+ else if (++__beg != __end)
+ {
+ __mod = __c;
+ __format = __ctype.narrow(*__beg, 0);
+ }
+ else
+ break;
+ __s = this->do_put(__s, __io, __fill, __tm,
+ __format, __mod);
+ }
+ else
+ break;
return __s;
}
do_put(iter_type __s, ios_base& __io, char_type, const tm* __tm,
char __format, char __mod) const
{
- locale __loc = __io.getloc();
+ const locale __loc = __io.getloc();
ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
__timepunct<_CharT> const& __tp = use_facet<__timepunct<_CharT> >(__loc);
// NB: This size is arbitrary. Should this be a data member,
// initialized at construction?
const size_t __maxlen = 64;
- char_type* __res =
- static_cast<char_type*>(__builtin_alloca(sizeof(char_type) * __maxlen));
+ char_type* __res = static_cast<char_type*>(__builtin_alloca(sizeof(char_type)
+ * __maxlen));
// NB: In IEE 1003.1-200x, and perhaps other locale models, it
// is possible that the format character will be longer than one
__tp._M_put(__res, __maxlen, __fmt, __tm);
// Write resulting, fully-formatted string to output iterator.
- size_t __len = char_traits<char_type>::length(__res);
- for (size_t __i = 0; __i < __len; ++__i, ++__s)
- *__s = __res[__i];
- return __s;
+ return std::__write(__s, __res, char_traits<char_type>::length(__res));
}
do_compare(const _CharT* __lo1, const _CharT* __hi1,
const _CharT* __lo2, const _CharT* __hi2) const
{
+ // strcoll assumes zero-terminated strings so we make a copy
+ // and then put a zero at the end.
const string_type __one(__lo1, __hi1);
const string_type __two(__lo2, __hi2);
- return _M_compare(__one.c_str(), __two.c_str());
+
+ const _CharT* __p = __one.c_str();
+ const _CharT* __pend = __one.data() + __one.length();
+ const _CharT* __q = __two.c_str();
+ const _CharT* __qend = __two.data() + __two.length();
+
+ // strcoll stops when it sees a nul character so we break
+ // the strings into zero-terminated substrings and pass those
+ // to strcoll.
+ for (;;)
+ {
+ const int __res = _M_compare(__p, __q);
+ if (__res)
+ return __res;
+
+ __p += char_traits<_CharT>::length(__p);
+ __q += char_traits<_CharT>::length(__q);
+ if (__p == __pend && __q == __qend)
+ return 0;
+ else if (__p == __pend)
+ return -1;
+ else if (__q == __qend)
+ return 1;
+
+ __p++;
+ __q++;
+ }
}
- template<typename _CharT>
+ template<typename _CharT>
typename collate<_CharT>::string_type
collate<_CharT>::
do_transform(const _CharT* __lo, const _CharT* __hi) const
{
+ // strxfrm assumes zero-terminated strings so we make a copy
+ string_type __str(__lo, __hi);
+
+ const _CharT* __p = __str.c_str();
+ const _CharT* __pend = __str.data() + __str.length();
+
size_t __len = (__hi - __lo) * 2;
- // First try a buffer perhaps big enough.
- _CharT* __c =
- static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __len));
- size_t __res = _M_transform(__c, __lo, __len);
- // If the buffer was not large enough, try again with the correct size.
- if (__res >= __len)
+
+ string_type __ret;
+
+ // strxfrm stops when it sees a nul character so we break
+ // the string into zero-terminated substrings and pass those
+ // to strxfrm.
+ for (;;)
{
- __c =
- static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__res + 1)));
- _M_transform(__c, __lo, __res + 1);
+ // First try a buffer perhaps big enough.
+ _CharT* __c =
+ static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __len));
+ size_t __res = _M_transform(__c, __p, __len);
+ // If the buffer was not large enough, try again with the
+ // correct size.
+ if (__res >= __len)
+ {
+ __len = __res + 1;
+ __c = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
+ * __len));
+ __res = _M_transform(__c, __p, __res + 1);
+ }
+
+ __ret.append(__c, __res);
+ __p += char_traits<_CharT>::length(__p);
+ if (__p == __pend)
+ return __ret;
+
+ __p++;
+ __ret.push_back(_CharT());
}
- return string_type(__c);
}
- template<typename _CharT>
+ template<typename _CharT>
long
collate<_CharT>::
do_hash(const _CharT* __lo, const _CharT* __hi) const
return static_cast<long>(__val);
}
- // Convert string to numeric value of type _Tv and store results.
- // NB: This is specialized for all required types, there is no
- // generic definition.
- template<typename _Tv>
- void
- __convert_to_v(const char* __in, _Tv& __out, ios_base::iostate& __err,
- const __c_locale& __cloc, int __base = 10);
-
- // Convert numeric value of type _Tv to string and return length of string.
- // If snprintf is available use it, otherwise fall back to the unsafe sprintf
- // which, in general, can be dangerous and should be avoided.
- template<typename _Tv>
- int
- __convert_from_v(char* __out, const int __size, const char* __fmt,
- _Tv __v, const __c_locale&, int __prec = -1);
-
// Construct correctly padded string, as per 22.2.2.2.2
// Assumes
// __newlen > __oldlen
// NB: Of the two parameters, _CharT can be deduced from the
// function arguments. The other (_Traits) has to be explicitly specified.
template<typename _CharT, typename _Traits>
- struct __pad
- {
- static void
- _S_pad(ios_base& __io, _CharT __fill, _CharT* __news,
- const _CharT* __olds, const streamsize __newlen,
- const streamsize __oldlen, const bool __num);
- };
-
- template<typename _CharT, typename _Traits>
void
__pad<_CharT, _Traits>::_S_pad(ios_base& __io, _CharT __fill,
_CharT* __news, const _CharT* __olds,
const streamsize __newlen,
const streamsize __oldlen, const bool __num)
{
- size_t __plen = static_cast<size_t>(__newlen - __oldlen);
- _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __plen));
- _Traits::assign(__pads, __plen, __fill);
-
- _CharT* __beg;
- _CharT* __end;
- size_t __mod = 0;
- size_t __beglen; //either __plen or __oldlen
- ios_base::fmtflags __adjust = __io.flags() & ios_base::adjustfield;
+ const size_t __plen = static_cast<size_t>(__newlen - __oldlen);
+ const ios_base::fmtflags __adjust = __io.flags() & ios_base::adjustfield;
+ // Padding last.
if (__adjust == ios_base::left)
{
- // Padding last.
- __beg = const_cast<_CharT*>(__olds);
- __beglen = __oldlen;
- __end = __pads;
+ _Traits::copy(__news, const_cast<_CharT*>(__olds), __oldlen);
+ _Traits::assign(__news + __oldlen, __plen, __fill);
+ return;
}
- else if (__adjust == ios_base::internal && __num)
+
+ size_t __mod = 0;
+ if (__adjust == ios_base::internal && __num)
{
// Pad after the sign, if there is one.
// Pad after 0[xX], if there is one.
// Who came up with these rules, anyway? Jeeze.
- locale __loc = __io.getloc();
+ const locale& __loc = __io._M_getloc();
const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
const _CharT __minus = __ctype.widen('-');
const _CharT __plus = __ctype.widen('+');
- bool __testsign = _Traits::eq(__olds[0], __minus)
- || _Traits::eq(__olds[0], __plus);
+ const bool __testsign = _Traits::eq(__olds[0], __minus)
+ || _Traits::eq(__olds[0], __plus);
- bool __testhex = _Traits::eq(__ctype.widen('0'), __olds[0])
- && (_Traits::eq(__ctype.widen('x'), __olds[1])
- || _Traits::eq(__ctype.widen('X'), __olds[1]));
+ const bool __testhex = _Traits::eq(__ctype.widen('0'), __olds[0])
+ && (_Traits::eq(__ctype.widen('x'), __olds[1])
+ || _Traits::eq(__ctype.widen('X'), __olds[1]));
if (__testhex)
{
__news[0] = __olds[0];
__news[1] = __olds[1];
- __mod += 2;
+ __mod = 2;
__news += 2;
- __beg = __pads;
- __beglen = __plen;
- __end = const_cast<_CharT*>(__olds + __mod);
}
else if (__testsign)
{
- _Traits::eq((__news[0] = __olds[0]), __plus) ? __plus : __minus;
- ++__mod;
+ __news[0] = __olds[0];
+ __mod = 1;
++__news;
- __beg = __pads;
- __beglen = __plen;
- __end = const_cast<_CharT*>(__olds + __mod);
- }
- else
- {
- // Padding first.
- __beg = __pads;
- __beglen = __plen;
- __end = const_cast<_CharT*>(__olds);
}
+ // else Padding first.
}
- else
- {
- // Padding first.
- __beg = __pads;
- __beglen = __plen;
- __end = const_cast<_CharT*>(__olds);
- }
- _Traits::copy(__news, __beg, __beglen);
- _Traits::copy(__news + __beglen, __end,
- __newlen - __beglen - __mod);
+ _Traits::assign(__news, __plen, __fill);
+ _Traits::copy(__news + __plen, const_cast<_CharT*>(__olds + __mod),
+ __oldlen - __mod);
}
- // Used by both numeric and monetary facets.
- // Check to make sure that the __grouping_tmp string constructed in
- // money_get or num_get matches the canonical grouping for a given
- // locale.
- // __grouping_tmp is parsed L to R
- // 1,222,444 == __grouping_tmp of "/1/3/3"
- // __grouping is parsed R to L
- // 1,222,444 == __grouping of "/3" == "/3/3/3"
template<typename _CharT>
bool
__verify_grouping(const basic_string<_CharT>& __grouping,
- basic_string<_CharT>& __grouping_tmp)
- {
- int __i = 0;
- int __j = 0;
- const int __len = __grouping.size();
- const int __n = __grouping_tmp.size();
+ const basic_string<_CharT>& __grouping_tmp)
+ {
+ 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;
}
- // Used by both numeric and monetary facets.
- // Inserts "group separator" characters into an array of characters.
- // It's recursive, one iteration per group. It moves the characters
- // in the buffer this way: "xxxx12345" -> "12,345xxx". Call this
- // only with __gbeg != __gend.
template<typename _CharT>
_CharT*
__add_grouping(_CharT* __s, _CharT __sep,
const _CharT* __first, const _CharT* __last)
{
if (__last - __first > *__gbeg)
- {
- __s = __add_grouping(__s, __sep,
- (__gbeg + 1 == __gend ? __gbeg : __gbeg + 1),
- __gend, __first, __last - *__gbeg);
- __first = __last - *__gbeg;
- *__s++ = __sep;
- }
+ {
+ const bool __bump = __gbeg + 1 != __gend;
+ __s = std::__add_grouping(__s, __sep, __gbeg + __bump,
+ __gend, __first, __last - *__gbeg);
+ __first = __last - *__gbeg;
+ *__s++ = __sep;
+ }
do
*__s++ = *__first++;
while (__first != __last);
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
// NB: This syntax is a GNU extension.
+#if _GLIBCXX_EXTERN_TEMPLATE
extern template class moneypunct<char, false>;
extern template class moneypunct<char, true>;
extern template class moneypunct_byname<char, false>;
bool
has_facet<messages<char> >(const locale&);
-#ifdef _GLIBCPP_USE_WCHAR_T
+#ifdef _GLIBCXX_USE_WCHAR_T
extern template class moneypunct<wchar_t, false>;
extern template class moneypunct<wchar_t, true>;
extern template class moneypunct_byname<wchar_t, false>;
bool
has_facet<messages<wchar_t> >(const locale&);
#endif
+#endif
} // namespace std
#endif