tinyxml2 icon indicating copy to clipboard operation
tinyxml2 copied to clipboard

Parsing attribute with numeric value "1 2" does not produce an error.

Open Levi-Armstrong opened this issue 6 years ago • 2 comments

If an attribute contains a numeric value with spaces like "1 2" and you use the parse to double you get the value 1. I would expect this to return an error. Is this the intended behavior?

Levi-Armstrong avatar Sep 18 '19 01:09 Levi-Armstrong

Hi @Levi-Armstrong , which version and API did you use?
I use the double XMLElement::DoubleAttribute(const char* name, double defaultValue) const in the master branch, but it seems the result is not the same as you descripe. I write an attribute contains a numeric value with spaces like "1 2" in an XML file as you descripe, but i got 1 rather than 12. Can you give more detail or code snippet about you issue?

Alanscut avatar Sep 18 '19 08:09 Alanscut

My mistake, I also get 1. Is this the expected behavior? I would still expect if the whole string is not a numeric value it would fail. I am not sure what is used to parse double from strings, but the code below produces my expected behavior.

std::stringstream ss;
ss.imbue(std::locale::classic());

ss << s;

double out;
ss >> out;

if (ss.fail() || !ss.eof())
  return false;

return true;

Levi-Armstrong avatar Sep 18 '19 14:09 Levi-Armstrong