Commit f4bdbead by Paolo Carlini Committed by Paolo Carlini

locale_facets.h (money_get<>::_M_extract): Change signature: now takes a plain string&.

2004-02-27  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/locale_facets.h (money_get<>::_M_extract):
	Change signature: now takes a plain string&.
	* include/bits/locale_facets.tcc (money_get<>::_M_extract):
	Update consistently the definition; use the moneypunct cache
	to parse the value; use swap to change __units.
	(money_get<>::do_get(long double&)): Update call of _M_extract,
	avoid ctype::narrow, not correct wrt the standard.
	(money_get<>::do_get(string_type&)): Likewise, update call
	of _M_extract, use ctype::widen.
	* src/locale-inst.cc: Tweak instantiations of _M_extract.

From-SVN: r78562
parent f6db1481
2004-02-27 Paolo Carlini <pcarlini@suse.de>
* include/bits/locale_facets.h (money_get<>::_M_extract):
Change signature: now takes a plain string&.
* include/bits/locale_facets.tcc (money_get<>::_M_extract):
Update consistently the definition; use the moneypunct cache
to parse the value; use swap to change __units.
(money_get<>::do_get(long double&)): Update call of _M_extract,
avoid ctype::narrow, not correct wrt the standard.
(money_get<>::do_get(string_type&)): Likewise, update call
of _M_extract, use ctype::widen.
* src/locale-inst.cc: Tweak instantiations of _M_extract.
2004-02-26 Ian Lance Taylor <ian@wasabisystems.com> 2004-02-26 Ian Lance Taylor <ian@wasabisystems.com>
* testsuite/demangle/abi_examples/01.cc: Expect error -2. * testsuite/demangle/abi_examples/01.cc: Expect error -2.
......
...@@ -4128,7 +4128,7 @@ namespace std ...@@ -4128,7 +4128,7 @@ namespace std
template<bool _Intl> template<bool _Intl>
iter_type iter_type
_M_extract(iter_type __s, iter_type __end, ios_base& __io, _M_extract(iter_type __s, iter_type __end, ios_base& __io,
ios_base::iostate& __err, string_type& __digits) const; ios_base::iostate& __err, string& __digits) const;
}; };
template<typename _CharT, typename _InIter> template<typename _CharT, typename _InIter>
......
...@@ -1163,8 +1163,9 @@ namespace std ...@@ -1163,8 +1163,9 @@ namespace std
_InIter _InIter
money_get<_CharT, _InIter>:: money_get<_CharT, _InIter>::
_M_extract(iter_type __beg, iter_type __end, ios_base& __io, _M_extract(iter_type __beg, iter_type __end, ios_base& __io,
ios_base::iostate& __err, string_type& __units) const ios_base::iostate& __err, string& __units) const
{ {
typedef char_traits<_CharT> __traits_type;
typedef typename string_type::size_type size_type; typedef typename string_type::size_type size_type;
typedef money_base::part part; typedef money_base::part part;
typedef moneypunct<_CharT, _Intl> __moneypunct_type; typedef moneypunct<_CharT, _Intl> __moneypunct_type;
...@@ -1193,12 +1194,13 @@ namespace std ...@@ -1193,12 +1194,13 @@ namespace std
bool __testdecfound = false; bool __testdecfound = false;
// The tentative returned string is stored here. // The tentative returned string is stored here.
string_type __res; string __res;
__res.reserve(20); __res.reserve(32);
const char_type* __lit_zero = __lit + _S_zero;
const char_type* __q;
for (int __i = 0; __beg != __end && __i < 4 && __testvalid; ++__i) for (int __i = 0; __beg != __end && __i < 4 && __testvalid; ++__i)
{ {
char_type __c;
const part __which = static_cast<part>(__p.field[__i]); const part __which = static_cast<part>(__p.field[__i]);
switch (__which) switch (__which)
{ {
...@@ -1257,12 +1259,12 @@ namespace std ...@@ -1257,12 +1259,12 @@ namespace std
// Extract digits, remove and stash away the // Extract digits, remove and stash away the
// grouping of found thousands separators. // grouping of found thousands separators.
for (; __beg != __end; ++__beg) for (; __beg != __end; ++__beg)
if (__ctype.is(ctype_base::digit, __c = *__beg)) if (__q = __traits_type::find(__lit_zero, 10, *__beg))
{ {
__res += __c; __res += _S_atoms[__q - __lit];
++__sep_pos; ++__sep_pos;
} }
else if (__c == __lc->_M_decimal_point && !__testdecfound) else if (*__beg == __lc->_M_decimal_point && !__testdecfound)
{ {
// If no grouping chars are seen, no grouping check // If no grouping chars are seen, no grouping check
// is applied. Therefore __grouping_tmp is adjusted // is applied. Therefore __grouping_tmp is adjusted
...@@ -1272,7 +1274,7 @@ namespace std ...@@ -1272,7 +1274,7 @@ namespace std
__sep_pos = 0; __sep_pos = 0;
__testdecfound = true; __testdecfound = true;
} }
else if (__c == __lc->_M_thousands_sep && !__testdecfound) else if (*__beg == __lc->_M_thousands_sep && !__testdecfound)
{ {
if (__lc->_M_grouping_size) if (__lc->_M_grouping_size)
{ {
...@@ -1358,7 +1360,7 @@ namespace std ...@@ -1358,7 +1360,7 @@ namespace std
if (!__testvalid) if (!__testvalid)
__err |= ios_base::failbit; __err |= ios_base::failbit;
else else
__units.assign(__res.data(), __res.size()); __units.swap(__res);
return __beg; return __beg;
} }
...@@ -1369,19 +1371,15 @@ namespace std ...@@ -1369,19 +1371,15 @@ namespace std
do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io, do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io,
ios_base::iostate& __err, long double& __units) const ios_base::iostate& __err, long double& __units) const
{ {
string_type __str; string __str;
if (__intl) if (__intl)
__beg = _M_extract<true>(__beg, __end, __io, __err, __str); __beg = _M_extract<true>(__beg, __end, __io, __err, __str);
else else
__beg = _M_extract<false>(__beg, __end, __io, __err, __str); __beg = _M_extract<false>(__beg, __end, __io, __err, __str);
const int __cs_size = __str.size() + 1; if (__str.size())
char* __cs = static_cast<char*>(__builtin_alloca(__cs_size)); std::__convert_to_v(__str.c_str(), __units, __err, _S_get_c_locale());
const locale __loc = __io.getloc();
const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
const _CharT* __wcs = __str.c_str();
__ctype.narrow(__wcs, __wcs + __cs_size, char(), __cs);
std::__convert_to_v(__cs, __units, __err, _S_get_c_locale());
return __beg; return __beg;
} }
...@@ -1390,8 +1388,28 @@ namespace std ...@@ -1390,8 +1388,28 @@ namespace std
money_get<_CharT, _InIter>:: money_get<_CharT, _InIter>::
do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io, do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io,
ios_base::iostate& __err, string_type& __units) const ios_base::iostate& __err, string_type& __units) const
{ return __intl ? _M_extract<true>(__beg, __end, __io, __err, __units) {
: _M_extract<false>(__beg, __end, __io, __err, __units); } typedef typename string_type::size_type size_type;
const locale& __loc = __io._M_getloc();
const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
string __str;
const iter_type __ret = __intl ? _M_extract<true>(__beg, __end, __io,
__err, __str)
: _M_extract<false>(__beg, __end, __io,
__err, __str);
const size_type __len = __str.size();
if (__len)
{
_CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
* __len));
__ctype.widen(__str.data(), __str.data() + __len, __ws);
__units.assign(__ws, __len);
}
return __ret;
}
template<typename _CharT, typename _OutIter> template<typename _CharT, typename _OutIter>
template<bool _Intl> template<bool _Intl>
......
...@@ -54,13 +54,13 @@ namespace std ...@@ -54,13 +54,13 @@ namespace std
istreambuf_iterator<C> istreambuf_iterator<C>
money_get<C, istreambuf_iterator<C> >:: money_get<C, istreambuf_iterator<C> >::
_M_extract<true>(istreambuf_iterator<C>, istreambuf_iterator<C>, _M_extract<true>(istreambuf_iterator<C>, istreambuf_iterator<C>,
ios_base&, ios_base::iostate&, string_type&) const; ios_base&, ios_base::iostate&, string&) const;
template template
istreambuf_iterator<C> istreambuf_iterator<C>
money_get<C, istreambuf_iterator<C> >:: money_get<C, istreambuf_iterator<C> >::
_M_extract<false>(istreambuf_iterator<C>, istreambuf_iterator<C>, _M_extract<false>(istreambuf_iterator<C>, istreambuf_iterator<C>,
ios_base&, ios_base::iostate&, string_type&) const; ios_base&, ios_base::iostate&, string&) const;
template template
ostreambuf_iterator<C> ostreambuf_iterator<C>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment