scpeters-test / sdformat

Simulation Description Format (SDF) parser and description files.
http://sdformat.org
Other
1 stars 0 forks source link

String trimming only considers space and tab #194

Open scpeters-test opened 6 years ago

scpeters-test commented 6 years ago

Original report (archived issue) by Sean Curtis (Bitbucket: SeanCurtisTRI).


In the sdf::trim function, it is trimming off leading and trailing space and tab characters. I'd recommend going further in capturing all characters that C++ considers to be whitespace. Something like:

std::string trim(const std::string& name) {
  std::regex trim_regex("^\\s*(.*?)\\s*$");
  std::smatch matches;
  std::regex_match(name, matches, trim_regex);
  return matches[1].str();
}

Also, we might want to consider what whitespace is allowed inside strings. It would be silly to have a name: "a\f\vb".