Skip to content

Commit

Permalink
Trim input before parsing values
Browse files Browse the repository at this point in the history
Signed-off-by: Addisu Z. Taddese <[email protected]>
  • Loading branch information
azeey committed Jun 2, 2020
1 parent fdecf77 commit 32b3d84
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/Param.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ bool Param::ValueFromString(const std::string &_value)
// comma for decimal position instead of a dot, making the conversion
// to fail. See bug #60 for more information. Force to use always C
setlocale(LC_NUMERIC, "C");

std::string tmp(_value);
std::string lowerTmp = lowercase(_value);
std::string trimmed = sdf::trim(_value);
std::string tmp(trimmed);
std::string lowerTmp = lowercase(trimmed);

// "true" and "false" doesn't work properly
if (lowerTmp == "true")
Expand Down Expand Up @@ -423,14 +423,7 @@ bool Param::ValueFromString(const std::string &_value)
this->dataPtr->typeName == "pose" ||
this->dataPtr->typeName == "Pose")
{
// if the value is an empty string or white space we avoid parsing since
// its considered a valid value
auto isWhiteSpace = [](unsigned char _c)
{
return std::isspace(_c);
};

if (!tmp.empty() || !std::all_of(tmp.begin(), tmp.end(), isWhiteSpace))
if (!tmp.empty())
{
return ParseUsingStringStream<ignition::math::Pose3d>(
tmp, this->dataPtr->key, this->dataPtr->value);
Expand Down

0 comments on commit 32b3d84

Please sign in to comment.