-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[model_io] Fix implicit dependency of URDF parsers on system locale #289
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,22 +21,28 @@ namespace iDynTree | |
{ | ||
|
||
|
||
bool inline stringToDouble(const std::string & inStr, double & outDouble) | ||
bool inline stringToDoubleWithClassicLocale(const std::string & inStr, double & outDouble) | ||
{ | ||
outDouble = std::atof(inStr.c_str()); | ||
return true; | ||
std::istringstream ss(inStr); | ||
ss.imbue(std::locale::classic()); | ||
ss >> outDouble; | ||
return !(ss.fail()); | ||
} | ||
|
||
bool inline stringToInt(const std::string & inStr, int & outInt) | ||
bool inline stringToIntWithClassicLocale(const std::string & inStr, int & outInt) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason for the code duplication? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, for historical reason the |
||
{ | ||
outInt = std::atoi(inStr.c_str()); | ||
return true; | ||
std::istringstream ss(inStr); | ||
ss.imbue(std::locale::classic()); | ||
ss >> outInt; | ||
return !(ss.fail()); | ||
} | ||
|
||
bool inline stringToUnsignedInt(const std::string & inStr, unsigned int & outInt) | ||
bool inline stringToUnsignedIntWithClassicLocale(const std::string & inStr, unsigned int & outInt) | ||
{ | ||
outInt = (unsigned int)std::atoi(inStr.c_str()); | ||
return true; | ||
std::istringstream ss(inStr); | ||
ss.imbue(std::locale::classic()); | ||
ss >> outInt; | ||
return !(ss.fail()); | ||
} | ||
|
||
std::string inline intToString(const int inInt) | ||
|
@@ -81,7 +87,7 @@ bool inline vector3FromString(const std::string & vector_str, Vector3 & out) | |
{ | ||
if (pieces[i] != ""){ | ||
double newDouble; | ||
if( stringToDouble(pieces[i],newDouble) ) | ||
if( stringToDoubleWithClassicLocale(pieces[i],newDouble) ) | ||
{ | ||
xyz.push_back(newDouble); | ||
} | ||
|
@@ -157,7 +163,7 @@ bool inline vector4FromString(const std::string & vector_str, Vector4 & out) | |
{ | ||
if (pieces[i] != ""){ | ||
double newDouble; | ||
if( stringToDouble(pieces[i],newDouble) ) | ||
if( stringToDoubleWithClassicLocale(pieces[i],newDouble) ) | ||
{ | ||
rgba.push_back(newDouble); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a curiosity, why not using a templated function now that inside there are no differences between the
toDouble
andtoInt
andtoUnsigned
functions?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I think we can do it once we fixed the bug.