locale independent util::parse_double
This commit is contained in:
@@ -267,3 +267,15 @@ int util::replaceAll(std::string& str, const std::string& from, const std::strin
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// replace it with std::from_chars in the far far future
|
||||
double util::parse_double(const std::string& str) {
|
||||
std::istringstream ss(str);
|
||||
ss.imbue(std::locale("C"));
|
||||
double d;
|
||||
ss >> d;
|
||||
if (ss.fail()) {
|
||||
throw std::runtime_error("invalid number format");
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ namespace util {
|
||||
extern std::vector<ubyte> base64_decode(const std::string& str);
|
||||
|
||||
extern int replaceAll(std::string& str, const std::string& from, const std::string& to);
|
||||
|
||||
extern double parse_double(const std::string& str);
|
||||
}
|
||||
|
||||
#endif // UTIL_STRINGUTIL_H_
|
||||
Reference in New Issue
Block a user