Refactor floating point code for num_get::do_get into a template. No functionality change
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@194080 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3b3108ec59
commit
5ffe591d55
112
include/locale
112
include/locale
@ -813,6 +813,11 @@ protected:
|
||||
ios_base::iostate& __err, long double& __v) const;
|
||||
virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
|
||||
ios_base::iostate& __err, void*& __v) const;
|
||||
|
||||
template <class _Fp>
|
||||
iter_type __do_get_floating_point
|
||||
(iter_type __b, iter_type __e, ios_base& __iob,
|
||||
ios_base::iostate& __err, _Fp& __v) const;
|
||||
};
|
||||
|
||||
template <class _CharT, class _InputIterator>
|
||||
@ -1234,12 +1239,15 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
|
||||
return __b;
|
||||
}
|
||||
|
||||
// floating point
|
||||
|
||||
template <class _CharT, class _InputIterator>
|
||||
template <class _Fp>
|
||||
_InputIterator
|
||||
num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
|
||||
num_get<_CharT, _InputIterator>::__do_get_floating_point(iter_type __b, iter_type __e,
|
||||
ios_base& __iob,
|
||||
ios_base::iostate& __err,
|
||||
float& __v) const
|
||||
_Fp& __v) const
|
||||
{
|
||||
// Stage 1, nothing to do
|
||||
// Stage 2
|
||||
@ -1277,7 +1285,7 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
|
||||
if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz)
|
||||
*__g_end++ = __dc;
|
||||
// Stage 3
|
||||
__v = __num_get_float<float>(__a, __a_end, __err);
|
||||
__v = __num_get_float<_Fp>(__a, __a_end, __err);
|
||||
// Digit grouping checked
|
||||
__check_grouping(__grouping, __g, __g_end, __err);
|
||||
// EOF checked
|
||||
@ -1286,6 +1294,16 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
|
||||
return __b;
|
||||
}
|
||||
|
||||
template <class _CharT, class _InputIterator>
|
||||
_InputIterator
|
||||
num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
|
||||
ios_base& __iob,
|
||||
ios_base::iostate& __err,
|
||||
float& __v) const
|
||||
{
|
||||
return this->__do_get_floating_point(__b, __e, __iob, __err, __v );
|
||||
}
|
||||
|
||||
template <class _CharT, class _InputIterator>
|
||||
_InputIterator
|
||||
num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
|
||||
@ -1293,49 +1311,7 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
|
||||
ios_base::iostate& __err,
|
||||
double& __v) const
|
||||
{
|
||||
// Stage 1, nothing to do
|
||||
// Stage 2
|
||||
char_type __atoms[32];
|
||||
char_type __decimal_point;
|
||||
char_type __thousands_sep;
|
||||
string __grouping = this->__stage2_float_prep(__iob, __atoms,
|
||||
__decimal_point,
|
||||
__thousands_sep);
|
||||
string __buf;
|
||||
__buf.resize(__buf.capacity());
|
||||
char* __a = &__buf[0];
|
||||
char* __a_end = __a;
|
||||
unsigned __g[__num_get_base::__num_get_buf_sz];
|
||||
unsigned* __g_end = __g;
|
||||
unsigned __dc = 0;
|
||||
bool __in_units = true;
|
||||
char __exp = 'E';
|
||||
for (; __b != __e; ++__b)
|
||||
{
|
||||
if (__a_end - __a == __buf.size())
|
||||
{
|
||||
size_t __tmp = __buf.size();
|
||||
__buf.resize(2*__buf.size());
|
||||
__buf.resize(__buf.capacity());
|
||||
__a = &__buf[0];
|
||||
__a_end = __a + __tmp;
|
||||
}
|
||||
if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end,
|
||||
__decimal_point, __thousands_sep,
|
||||
__grouping, __g, __g_end,
|
||||
__dc, __atoms))
|
||||
break;
|
||||
}
|
||||
if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz)
|
||||
*__g_end++ = __dc;
|
||||
// Stage 3
|
||||
__v = __num_get_float<double>(__a, __a_end, __err);
|
||||
// Digit grouping checked
|
||||
__check_grouping(__grouping, __g, __g_end, __err);
|
||||
// EOF checked
|
||||
if (__b == __e)
|
||||
__err |= ios_base::eofbit;
|
||||
return __b;
|
||||
return this->__do_get_floating_point(__b, __e, __iob, __err, __v );
|
||||
}
|
||||
|
||||
template <class _CharT, class _InputIterator>
|
||||
@ -1345,49 +1321,7 @@ num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
|
||||
ios_base::iostate& __err,
|
||||
long double& __v) const
|
||||
{
|
||||
// Stage 1, nothing to do
|
||||
// Stage 2
|
||||
char_type __atoms[32];
|
||||
char_type __decimal_point;
|
||||
char_type __thousands_sep;
|
||||
string __grouping = this->__stage2_float_prep(__iob, __atoms,
|
||||
__decimal_point,
|
||||
__thousands_sep);
|
||||
string __buf;
|
||||
__buf.resize(__buf.capacity());
|
||||
char* __a = &__buf[0];
|
||||
char* __a_end = __a;
|
||||
unsigned __g[__num_get_base::__num_get_buf_sz];
|
||||
unsigned* __g_end = __g;
|
||||
unsigned __dc = 0;
|
||||
bool __in_units = true;
|
||||
char __exp = 'E';
|
||||
for (; __b != __e; ++__b)
|
||||
{
|
||||
if (__a_end - __a == __buf.size())
|
||||
{
|
||||
size_t __tmp = __buf.size();
|
||||
__buf.resize(2*__buf.size());
|
||||
__buf.resize(__buf.capacity());
|
||||
__a = &__buf[0];
|
||||
__a_end = __a + __tmp;
|
||||
}
|
||||
if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end,
|
||||
__decimal_point, __thousands_sep,
|
||||
__grouping, __g, __g_end,
|
||||
__dc, __atoms))
|
||||
break;
|
||||
}
|
||||
if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz)
|
||||
*__g_end++ = __dc;
|
||||
// Stage 3
|
||||
__v = __num_get_float<long double>(__a, __a_end, __err);
|
||||
// Digit grouping checked
|
||||
__check_grouping(__grouping, __g, __g_end, __err);
|
||||
// EOF checked
|
||||
if (__b == __e)
|
||||
__err |= ios_base::eofbit;
|
||||
return __b;
|
||||
return this->__do_get_floating_point(__b, __e, __iob, __err, __v );
|
||||
}
|
||||
|
||||
template <class _CharT, class _InputIterator>
|
||||
|
Loading…
x
Reference in New Issue
Block a user