Browse Source
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.
pull/4/head
Wladimir J. van der Laan
9 years ago
committed by
Jack Grigg
No known key found for this signature in database
GPG Key ID: 6A6914DAFBEA00DA
1 changed files with
6 additions and
5 deletions
-
src/utilstrencodings.cpp
|
@ -480,11 +480,12 @@ bool ParseDouble(const std::string& str, double *out) |
|
|
return false; |
|
|
return false; |
|
|
if (str.size() >= 2 && str[0] == '0' && str[1] == 'x') // No hexadecimal floats allowed
|
|
|
if (str.size() >= 2 && str[0] == '0' && str[1] == 'x') // No hexadecimal floats allowed
|
|
|
return false; |
|
|
return false; |
|
|
char *endp = NULL; |
|
|
std::istringstream text(str); |
|
|
errno = 0; // strtod will not set errno if valid
|
|
|
text.imbue(std::locale::classic()); |
|
|
double n = strtod(str.c_str(), &endp); |
|
|
double result; |
|
|
if(out) *out = n; |
|
|
text >> result; |
|
|
return endp && *endp == 0 && !errno; |
|
|
if(out) *out = result; |
|
|
|
|
|
return text.eof() && !text.fail(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string FormatParagraph(const std::string in, size_t width, size_t indent) |
|
|
std::string FormatParagraph(const std::string in, size_t width, size_t indent) |
|
|