mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
locale independent util::parse_double
This commit is contained in:
parent
84e8fd1af6
commit
bc72742ee3
20 changed files with 140 additions and 48 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue