Skip to content

Commit

Permalink
Add an override for sdf::trim that takes a std::string
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 a7b244c commit fdecf77
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions include/sdf/Types.hh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ namespace sdf
SDFORMAT_VISIBLE
std::string trim(const char *_in);

/// \brief Trim leading and trailing whitespace from a string.
/// \param[in] _in The string to trim.
/// \return A string containing the trimmed value.
SDFORMAT_VISIBLE
std::string trim(const std::string &_in);

/// \brief check if two values are equal, within a tolerance
/// \param[in] _a the first value
/// \param[in] _b the second value
Expand Down
12 changes: 8 additions & 4 deletions src/Types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,21 @@ std::vector<std::string> split(const std::string &_str,
//////////////////////////////////////////////////
std::string trim(const char *_in)
{
std::string str(_in);
return sdf::trim(std::string(_in));
}

const size_t strBegin = str.find_first_not_of(" \t");
//////////////////////////////////////////////////
std::string trim(const std::string &_in)
{
const size_t strBegin = _in.find_first_not_of(" \t");
if (strBegin == std::string::npos)
{
return "";
}

const size_t strRange = str.find_last_not_of(" \t") - strBegin + 1;
const size_t strRange = _in.find_last_not_of(" \t") - strBegin + 1;

return str.substr(strBegin, strRange);
return _in.substr(strBegin, strRange);
}

/////////////////////////////////////////////////
Expand Down

0 comments on commit fdecf77

Please sign in to comment.