diff --git a/iguana/json_reader.hpp b/iguana/json_reader.hpp index 6a86025b..d9d4c0e0 100644 --- a/iguana/json_reader.hpp +++ b/iguana/json_reader.hpp @@ -69,7 +69,7 @@ IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end) { IGUANA_UNLIKELY { throw std::runtime_error("Failed to parse number"); } const auto start = &*it; auto [p, ec] = detail::from_chars(start, start + size, value); - if (ec != std::errc{}) + if (ec != std::errc{} || *p == '.') IGUANA_UNLIKELY { throw std::runtime_error("Failed to parse number"); } it += (p - &*it); } @@ -193,11 +193,13 @@ IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end) { else { while (it != end) { switch (*it) { - IGUANA_UNLIKELY case '\\' : ++it; + IGUANA_UNLIKELY case '\\': + ++it; parse_escape(value, it, end); break; - // IGUANA_UNLIKELY case ']' : return; - IGUANA_UNLIKELY case '"' : ++it; + // IGUANA_UNLIKELY case ']' : return; + IGUANA_UNLIKELY case '"': + ++it; return; IGUANA_LIKELY default : value.push_back(*it); ++it; diff --git a/test/test.cpp b/test/test.cpp index 79b5240a..616e3441 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -179,6 +179,25 @@ struct nest_t { }; REFLECTION(nest_t, name, value, var); +struct point_t1 { + int x; + int y; +}; +REFLECTION(point_t1, x, y); + +TEST_CASE("test double to int") { + point_t p{1, 0.45}; + std::string s; + iguana::to_json(p, s); + std::cout << s << std::endl; + point_t1 p2; + CHECK_THROWS(iguana::from_json(p2, s)); + + point_t p3; + iguana::from_json(p3, s); + CHECK(p.y == p3.y); +} + TEST_CASE("test variant") { std::variant var; var = 1;