mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Merge pull request #2106 from Capostrophic/fallback
Revert to lexical cast for string-to-float conversion
This commit is contained in:
commit
5e541c1ae1
@ -2,6 +2,8 @@
|
||||
|
||||
#include <components/debug/debuglog.hpp>
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
namespace Fallback
|
||||
{
|
||||
Map::Map(const std::map<std::string,std::string>& fallback):mFallbackMap(fallback)
|
||||
@ -24,9 +26,11 @@ namespace Fallback
|
||||
{
|
||||
try
|
||||
{
|
||||
return std::stof(fallback);
|
||||
// We have to rely on Boost because std::stof from C++11
|
||||
// uses the current locale for separators which we don't want and often silently ignores parsing errors.
|
||||
return boost::lexical_cast<float>(fallback);
|
||||
}
|
||||
catch (const std::invalid_argument&)
|
||||
catch (boost::bad_lexical_cast&)
|
||||
{
|
||||
Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is not a valid number, using 0 as a fallback";
|
||||
}
|
||||
@ -48,6 +52,10 @@ namespace Fallback
|
||||
{
|
||||
Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is not a valid number, using 0 as a fallback";
|
||||
}
|
||||
catch (const std::out_of_range&)
|
||||
{
|
||||
Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is out of range, using 0 as a fallback";
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user