| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- //
- // json_common.h
- // json
- //
- // Created by Sam Jaffe on 4/22/16.
- //
- #pragma once
- #include <cstdlib>
- #include <stdexcept>
- #include <string>
- 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 <typename T>
- void parse_string(T& json, char const*& data) {
- json = parse_string(data);
- }
-
- template <typename T>
- 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;
- }
- }
- }
-
- }
- }
|