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_to_flatbuffer_test.cc b/aos/json_to_flatbuffer_test.cc
index 9dc12d2..aa259df 100644
--- a/aos/json_to_flatbuffer_test.cc
+++ b/aos/json_to_flatbuffer_test.cc
@@ -79,10 +79,20 @@
   EXPECT_TRUE(JsonAndBack("{ \"foo_enum_nonconsecutive\": \"Big\" }"));
 }
 
+// Tests that Inf is handled correctly
+TEST_F(JsonToFlatbufferTest, Inf) {
+  EXPECT_TRUE(JsonAndBack("{ \"foo_float\": inf }"));
+  EXPECT_TRUE(JsonAndBack("{ \"foo_float\": -inf }"));
+  EXPECT_TRUE(JsonAndBack("{ \"foo_double\": inf }"));
+  EXPECT_TRUE(JsonAndBack("{ \"foo_double\": -inf }"));
+}
+
 // Tests that NaN is handled correctly
 TEST_F(JsonToFlatbufferTest, Nan) {
   EXPECT_TRUE(JsonAndBack("{ \"foo_float\": nan }"));
   EXPECT_TRUE(JsonAndBack("{ \"foo_float\": -nan }"));
+  EXPECT_TRUE(JsonAndBack("{ \"foo_double\": nan }"));
+  EXPECT_TRUE(JsonAndBack("{ \"foo_double\": -nan }"));
 }
 
 // Tests that we can handle decimal points.
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) {