From adc659f58bd2cda4de64a39af05b866220cb8fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 25 Feb 2017 21:58:09 +0100 Subject: [PATCH] Fixed #7897 (MathLib::toDoubleValue: Does not handle character literal) --- lib/mathlib.cpp | 6 ++++-- test/testmathlib.cpp | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index 4221fa6c0..f11bac912 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -537,13 +537,15 @@ MathLib::bigint MathLib::toLongNumber(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)) return static_cast(toLongNumber(str)); // nullcheck - else if (isNullValue(str)) + if (isNullValue(str)) return 0.0; #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 return std::strtod(str.c_str(), 0); #endif diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index fa0348d94..8ca4f73ff 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -366,6 +366,7 @@ private: 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' , MathLib::toDoubleNumber("'0'")); // verify: string --> double --> string conversion ASSERT_EQUALS("1.0" , MathLib::toString(MathLib::toDoubleNumber("1.0f")));