From 64e2f93f385d5ab5e014a984ebbbd2995c5466cb Mon Sep 17 00:00:00 2001 From: mathieui Date: Wed, 20 Jan 2016 22:04:42 +0100 Subject: [PATCH] [Pipe input] Make the commands locale-unaware Setting axis values in an automated way should not be locale-aware as strtod is. --- .../ControllerInterface/Pipes/Pipes.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Source/Core/InputCommon/ControllerInterface/Pipes/Pipes.cpp b/Source/Core/InputCommon/ControllerInterface/Pipes/Pipes.cpp index e98e31ac9f..cff69fabfc 100644 --- a/Source/Core/InputCommon/ControllerInterface/Pipes/Pipes.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Pipes/Pipes.cpp @@ -6,7 +6,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -50,6 +52,16 @@ static const std::array s_axis_tokens "C" }}; +static double StringToDouble(const std::string& text) +{ + std::istringstream is(text); + // ignore current locale + is.imbue(std::locale::classic()); + double result; + is >> result; + return result; +} + void Init(std::vector& devices) { // Search the Pipes directory for files that we can open in read-only, @@ -161,13 +173,13 @@ void PipeDevice::ParseCommand(const std::string& command) { if (tokens.size() == 3) { - double value = strtod(tokens[2].c_str(), nullptr); + double value = StringToDouble(tokens[2]); SetAxis(tokens[1], (value / 2.0) + 0.5); } else if (tokens.size() == 4) { - double x = strtod(tokens[2].c_str(), nullptr); - double y = strtod(tokens[3].c_str(), nullptr); + double x = StringToDouble(tokens[2]); + double y = StringToDouble(tokens[3]); SetAxis(tokens[1] + " X", x); SetAxis(tokens[1] + " Y", y); }