Skip to content

Commit

Permalink
[config] parse floats (hopefully) without locale issues
Browse files Browse the repository at this point in the history
  • Loading branch information
DadSchoorse committed Jun 23, 2020
1 parent 54b3c63 commit d845000
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/config.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "config.hpp"

#include <sstream>
#include <locale>

namespace vkBasalt
{
Expand Down Expand Up @@ -125,13 +126,20 @@ namespace vkBasalt
auto found = options.find(option);
if (found != options.end())
{
try
// TODO find a better float parsing way, std::stof has locale issues
std::stringstream ss(found->second);
ss.imbue(std::locale("C"));
float value;
ss >> value;
std::string rest;
ss >> rest;
if (ss.fail() || (!rest.empty() && rest != "f"))
{
result = std::stof(found->second);
Logger::warn("invalid float value for: " + option);
}
catch (...)
else
{
Logger::warn("invalid float value for: " + option);
result = value;
}
}
}
Expand Down

0 comments on commit d845000

Please sign in to comment.