// // json_common.h // json // // Created by Sam Jaffe on 4/22/16. // #pragma once #include #include #include namespace json { class malformed_json_exception : public std::domain_error { using std::domain_error::domain_error; }; } namespace json { namespace helper { const char get_next_element(char const*& data); /** * @throws json::malformed_json_exception */ void advance_to_boundary(char const endtok, char const*& data); /** * @throws json::malformed_json_exception */ std::string parse_string(char const * & data); template void parse_string(T& json, char const*& data) { json = parse_string(data); } template void parse_numeric(T& json, char const*& data) { // TODO: more sophisticated float detection? char const* start = data; while (*++data) { if (*data == '.') { while (isnumber(*++data)); json = atof(start); break; } else if (!isnumber(*data)) { json = atoi(start); break; } } } } }