Support inf and -inf as well
Turns out if you serialize a schema to json which has a default of
infinity, you can't deserialize it again. Add support for the infinity
there.
Change-Id: I4b55a293ffbbde118b33f5cc90f4e22cf43d19d9
diff --git a/aos/json_tokenizer.cc b/aos/json_tokenizer.cc
index 9403daa..47fcdbe 100644
--- a/aos/json_tokenizer.cc
+++ b/aos/json_tokenizer.cc
@@ -152,6 +152,12 @@
return true;
}
+ // Inf is also acceptable.
+ if (Consume("inf")) {
+ *s = ::std::string(original.substr(0, original.size() - data_.size()));
+ return true;
+ }
+
// Then, we either get a 0, or we get a nonzero. Only nonzero can be followed
// by a second number.
if (!Consume("0")) {
@@ -463,6 +469,14 @@
return true;
}
+ if (field_value() == "inf") {
+ *value = std::numeric_limits<double>::infinity();
+ return true;
+ } else if (field_value() == "-inf") {
+ *value = -std::numeric_limits<double>::infinity();
+ return true;
+ }
+
*value = strtod(field_value().c_str(), const_cast<char **>(&pos));
if (pos != field_value().c_str() + field_value().size() || errno != 0) {