[Pipe input] Make the commands locale-unaware
Setting axis values in an automated way should not be locale-aware as strtod is.
This commit is contained in:
parent
f98176f38a
commit
64e2f93f38
|
@ -6,7 +6,9 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <locale>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -50,6 +52,16 @@ static const std::array<std::string, 2> s_axis_tokens
|
||||||
"C"
|
"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<Core::Device*>& devices)
|
void Init(std::vector<Core::Device*>& devices)
|
||||||
{
|
{
|
||||||
// Search the Pipes directory for files that we can open in read-only,
|
// 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)
|
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);
|
SetAxis(tokens[1], (value / 2.0) + 0.5);
|
||||||
}
|
}
|
||||||
else if (tokens.size() == 4)
|
else if (tokens.size() == 4)
|
||||||
{
|
{
|
||||||
double x = strtod(tokens[2].c_str(), nullptr);
|
double x = StringToDouble(tokens[2]);
|
||||||
double y = strtod(tokens[3].c_str(), nullptr);
|
double y = StringToDouble(tokens[3]);
|
||||||
SetAxis(tokens[1] + " X", x);
|
SetAxis(tokens[1] + " X", x);
|
||||||
SetAxis(tokens[1] + " Y", y);
|
SetAxis(tokens[1] + " Y", y);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue