// // json_binder.cpp // json // // Created by Sam Jaffe on 4/23/16. // #include "json_common.hpp" namespace json { namespace helper { namespace { std::string get_no_end_error(char expected, char found) { char str[64] = { '\0' }; snprintf(str, sizeof(str), "Expected delimeter: ',' or '%c', got '%c' instead", expected, found); return str; } } const char get_next_element(char const*& data) { while (isspace(*data)) ++data; return *data; } void advance_to_boundary(char const endtok, char const*& data) { char const next = get_next_element(data); if (next == ',') { ++data; } else if (next != endtok) { throw json::malformed_json_exception(get_no_end_error(endtok, *data)); } } std::string parse_string(char const * & data) { char const* start = data; while (*++data) { if (*data == '"' && *(data-1) != '\\') { return std::string(start+1, data++); } } throw json::malformed_json_exception("Could not locate end of string"); } } }