Skip to content

Commit

Permalink
fix for number
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Apr 9, 2024
1 parent 5857afd commit 21a6dc9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
10 changes: 6 additions & 4 deletions iguana/json_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, std::string> var;
var = 1;
Expand Down

0 comments on commit 21a6dc9

Please sign in to comment.