// zeros, however this produces strings without decimal points
// for whole number values. When reparsed this will create
// IntElements not DoubleElements. Rather than used a fixed
- // precision, we'll just tack on an ".0" when the decimal point
- // is missing.
+ // precision, we'll just tack on an ".0" when there is no
+ // fractional nor exponent parts.
ostringstream val_ss;
val_ss << doubleValue();
ss << val_ss.str();
- if (val_ss.str().find_first_of('.') == string::npos) {
+ if (val_ss.str().find_first_of(".eE") == string::npos) {
ss << ".0";
}
}
sv.push_back("-1");
sv.push_back("-1.234");
sv.push_back("-123.456");
+ sv.push_back("1e+30");
// We should confirm that our string handling is 8-bit clean.
// At one point we were using char-length data and comparing to EOF,
// which means that character '\xFF' would not parse properly.
EXPECT_EQ("0.01", Element::fromJSON("1.0e-2")->str());
EXPECT_EQ("0.012", Element::fromJSON("1.2e-2")->str());
EXPECT_EQ("0.012", Element::fromJSON("1.2E-2")->str());
+ EXPECT_EQ("1e+30", Element::fromJSON("1e30")->str());
+ EXPECT_EQ("1e+30", Element::fromJSON("1E30")->str());
+ EXPECT_EQ("1e+30", Element::fromJSON("1E+30")->str());
+ EXPECT_EQ("1e-30", Element::fromJSON("1E-30")->str());
EXPECT_EQ("\"\"", Element::fromJSON(" \n \t \r \f \b \"\" \n \f \t \r \b")->str());
EXPECT_EQ("{ }", Element::fromJSON("{ \n \r \t \b \f }")->str());
EXPECT_EQ("[ ]", Element::fromJSON("[ \n \r \f \t \b ]")->str());