Boost-Geometry-Utils
view release on metacpan or search on metacpan
src/boost/lexical_cast.hpp view on Meta::CPAN
* Digit grouping is checked. That is, the positions of discarded
* separators is examined for consistency with
* use_facet<numpunct<charT> >(loc ).grouping()
*
* BUT what if there is no separators at all and grouping()
* is not empty? Well, we have no extraced separators, so we
* won`t check them for consistency. This will allow us to
* work with "C" locale from other locales
*/
shall_we_return = false;
break;
} else {
if ( begin == end ) return false;
if (current_grouping < grouping_size-1 ) ++current_grouping;
remained = grouping[current_grouping];
}
}
}
if (shall_we_return) return true;
}
}
#endif
{
while ( begin <= end )
{
T const multiplier_10 = multiplier * 10;
if (multiplier_10 / 10 != multiplier) multiplier_overflowed = true;
T const dig_value = *end - czero;
T const new_sub_value = multiplier_10 * dig_value;
if (*end < czero || *end >= czero + 10
/* detecting overflow */
|| (dig_value && new_sub_value / dig_value != multiplier_10)
|| static_cast<T>((std::numeric_limits<T>::max)()-new_sub_value) < value
|| (multiplier_overflowed && dig_value)
)
return false;
value += new_sub_value;
multiplier *= 10;
--end;
}
}
return true;
}
}
namespace detail
{
template <class CharT>
bool lc_iequal(const CharT* val, const CharT* lcase, const CharT* ucase, unsigned int len) BOOST_NOEXCEPT {
for( unsigned int i=0; i < len; ++i ) {
if ( val[i] != lcase[i] && val[i] != ucase[i] ) return false;
}
return true;
}
/* Returns true and sets the correct value if found NaN or Inf. */
template <class CharT, class T>
inline bool parse_inf_nan_impl(const CharT* begin, const CharT* end, T& value
, const CharT* lc_NAN, const CharT* lc_nan
, const CharT* lc_INFINITY, const CharT* lc_infinity
, const CharT opening_brace, const CharT closing_brace) BOOST_NOEXCEPT
{
using namespace std;
if (begin == end) return false;
const CharT minus = lcast_char_constants<CharT>::minus;
const CharT plus = lcast_char_constants<CharT>::plus;
const int inifinity_size = 8;
bool has_minus = false;
/* Parsing +/- */
if( *begin == minus)
{
++ begin;
has_minus = true;
}
else if( *begin == plus ) ++begin;
if( end-begin < 3 ) return false;
if( lc_iequal(begin, lc_nan, lc_NAN, 3) )
{
begin += 3;
if (end != begin) /* It is 'nan(...)' or some bad input*/
{
if(end-begin<2) return false; // bad input
-- end;
if( *begin != opening_brace || *end != closing_brace) return false; // bad input
}
if( !has_minus ) value = std::numeric_limits<T>::quiet_NaN();
else value = (boost::math::changesign) (std::numeric_limits<T>::quiet_NaN());
return true;
} else
if (( /* 'INF' or 'inf' */
end-begin==3
&&
lc_iequal(begin, lc_infinity, lc_INFINITY, 3)
)
||
( /* 'INFINITY' or 'infinity' */
end-begin==inifinity_size
&&
lc_iequal(begin, lc_infinity, lc_INFINITY, inifinity_size)
)
)
{
if( !has_minus ) value = std::numeric_limits<T>::infinity();
else value = (boost::math::changesign) (std::numeric_limits<T>::infinity());
return true;
}
return false;
}
template <class CharT, class T>
bool put_inf_nan_impl(CharT* begin, CharT*& end, const T& value
, const CharT* lc_nan
, const CharT* lc_infinity) BOOST_NOEXCEPT
{
using namespace std;
const CharT minus = lcast_char_constants<CharT>::minus;
if ( (boost::math::isnan)(value) )
{
if ( (boost::math::signbit)(value) )
{
*begin = minus;
++ begin;
}
memcpy(begin, lc_nan, 3 * sizeof(CharT));
end = begin + 3;
return true;
} else if ( (boost::math::isinf)(value) )
{
if ( (boost::math::signbit)(value) )
{
*begin = minus;
++ begin;
}
memcpy(begin, lc_infinity, 3 * sizeof(CharT));
end = begin + 3;
return true;
}
return false;
}
#ifndef BOOST_LCAST_NO_WCHAR_T
template <class T>
( run in 1.756 second using v1.01-cache-2.11-cpan-39bf76dae61 )