Fixed #7897 (MathLib::toDoubleValue: Does not handle character literal)

This commit is contained in:
Daniel Marjamäki 2017-02-25 21:58:09 +01:00
parent 26fc7abfac
commit adc659f58b
2 changed files with 5 additions and 2 deletions

View File

@ -537,13 +537,15 @@ MathLib::bigint MathLib::toLongNumber(const std::string & str)
double MathLib::toDoubleNumber(const std::string &str) double MathLib::toDoubleNumber(const std::string &str)
{ {
if (str[0] == '\'' && str.size() >= 3U && str.back() == '\'')
return characterLiteralToLongNumber(str.substr(1,str.size()-2));
if (isIntHex(str)) if (isIntHex(str))
return static_cast<double>(toLongNumber(str)); return static_cast<double>(toLongNumber(str));
// nullcheck // nullcheck
else if (isNullValue(str)) if (isNullValue(str))
return 0.0; return 0.0;
#ifdef __clang__ #ifdef __clang__
else if (isFloat(str)) // Workaround libc++ bug at http://llvm.org/bugs/show_bug.cgi?id=17782 if (isFloat(str)) // Workaround libc++ bug at http://llvm.org/bugs/show_bug.cgi?id=17782
// TODO : handle locale // TODO : handle locale
return std::strtod(str.c_str(), 0); return std::strtod(str.c_str(), 0);
#endif #endif

View File

@ -366,6 +366,7 @@ private:
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("+0.")); ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("+0."));
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("-0.0")); ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("-0.0"));
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("+0.0")); ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("+0.0"));
ASSERT_EQUALS_DOUBLE('0' , MathLib::toDoubleNumber("'0'"));
// verify: string --> double --> string conversion // verify: string --> double --> string conversion
ASSERT_EQUALS("1.0" , MathLib::toString(MathLib::toDoubleNumber("1.0f"))); ASSERT_EQUALS("1.0" , MathLib::toString(MathLib::toDoubleNumber("1.0f")));