Browse Source

Make binder constructors implicit for convenience.
Make tuple_binder throw if there are more elements than expected.
Make int/double/string parsers discard leading spaces.

Samuel Jaffe 8 years ago
parent
commit
ff7096827d
3 changed files with 7 additions and 3 deletions
  1. 2 1
      json/json_tuple_binder.hpp
  2. 2 2
      json_binder.hpp
  3. 3 0
      json_common.hpp

+ 2 - 1
json/json_tuple_binder.hpp

@@ -51,7 +51,8 @@ namespace json { namespace binder {
       if (it != members.end()) {
         throw json::malformed_json_exception("Failed to parse every member of tuple");
       }
-      if (*data) ++data;
+      if (*data != ']') throw json::malformed_json_exception("Parsed every tuple element, but did not reach end");
+      else if (*data) ++data;
       else throw json::unterminated_json_exception("Reached end of parse string without finding array end");
     }
     

+ 2 - 2
json_binder.hpp

@@ -33,8 +33,8 @@ namespace json {
     public:
       binder() : impl(nullptr) {}
       binder(binder const& other) : impl(other.impl->clone()) {}
-      explicit binder(binder_impl<T> const* p) : impl(p) {}
-      explicit binder(binder_impl<T> const& r) : impl(r.clone()) {}
+      binder(binder_impl<T> const* p) : impl(p) {}
+      binder(binder_impl<T> const& r) : impl(r.clone()) {}
       
       ~binder() { delete impl; }
       

+ 3 - 0
json_common.hpp

@@ -102,6 +102,7 @@ namespace json { namespace helper {
   
   template <typename T>
   void parse_string(T& json, char const * & data) {
+    json::helper::get_next_element(data);
     json = parse_string(data);
   }
   
@@ -120,6 +121,7 @@ namespace json { namespace helper {
   
   template <typename T>
   void parse_double(T& json, char const * & data) {
+    json::helper::get_next_element(data);
     char const * begin = data;
     errno = 0;
     T tmp = parse_double_impl<T>(begin, data);
@@ -134,6 +136,7 @@ namespace json { namespace helper {
   
   template <typename J>
   void parse_numeric(J & json, char const * & data) {
+    json::helper::get_next_element(data);
     numeric_token_info info = data;
     if ( info.is_negative && !std::is_signed<J>::value ) {
       throw json_numeric_exception{"Expected signed integer"};