aboutsummaryrefslogtreecommitdiff
path: root/src/utilstrencodings.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2015-07-18 08:16:21 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2015-07-18 09:04:18 +0200
commitec249d4a1d572a17dd010464fe3ead532a8b1b70 (patch)
tree26bb1be16831c3e74a13975c661c3d6cb4b7b561 /src/utilstrencodings.cpp
parent7650449a6777710cf818d41862626164da0cd412 (diff)
util: use locale-independent parsing in ParseDouble
Use locale-indepent C++ based parsing instead of C's strtod, which checks for different input based on the user's locale. Fixes #6443.
Diffstat (limited to 'src/utilstrencodings.cpp')
-rw-r--r--src/utilstrencodings.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp
index 7208ca9474..1f7a2cae2c 100644
--- a/src/utilstrencodings.cpp
+++ b/src/utilstrencodings.cpp
@@ -464,11 +464,12 @@ bool ParseDouble(const std::string& str, double *out)
return false;
if (str.size() >= 2 && str[0] == '0' && str[1] == 'x') // No hexadecimal floats allowed
return false;
- char *endp = NULL;
- errno = 0; // strtod will not set errno if valid
- double n = strtod(str.c_str(), &endp);
- if(out) *out = n;
- return endp && *endp == 0 && !errno;
+ std::istringstream text(str);
+ text.imbue(std::locale::classic());
+ double result;
+ text >> result;
+ if(out) *out = result;
+ return text.eof() && !text.fail();
}
std::string FormatParagraph(const std::string& in, size_t width, size_t indent)