diff --git a/src/library/jsonincpp/parser.cpp b/src/library/jsonincpp/parser.cpp index 29613a7..8b46e9d 100644 --- a/src/library/jsonincpp/parser.cpp +++ b/src/library/jsonincpp/parser.cpp @@ -43,7 +43,7 @@ namespace json { break; skip(pctx); if (ch == '0' && d == 0) - break; + return; if (d < 18) { mantis_max18 = mantis_max18 * 10 + (ch - '0'); d++; @@ -208,37 +208,25 @@ namespace json { return NULL; } - int parse_str(const std::string& text, JSON& ret_ans, WrongSyntax& ret_error) { - assert(ret_ans.isNull()); - ParserContext pctx(text); - try { - std::vector> callStack; - callStack.push_back(std::make_unique(ret_ans)); - while (!callStack.empty()) { - std::unique_ptr rt = callStack.back()->here(pctx); - if (rt) { - callStack.push_back(std::move(rt)); - } else { - callStack.pop_back(); - } - } - skipWhitespaces(pctx); - if (!isEof(pctx)) - throw bad_syntax(); - return 0; - } catch (bad_syntax&) { - ret_error.line = pctx.line; - ret_error.column = pctx.column; - return -1; - } - } - JSON parse_str_flawless(const std::string &text) { WrongSyntax wsErr; + ParserContext pctx(text); JSON result; - int ret = parse_str(text, result, wsErr); - if (ret < 0) - throw misuse("JSON parsing error"); + + std::vector> callStack; + callStack.push_back(std::make_unique(result)); + while (!callStack.empty()) { + std::unique_ptr rt = callStack.back()->here(pctx); + if (rt) { + callStack.push_back(std::move(rt)); + } else { + callStack.pop_back(); + } + } + skipWhitespaces(pctx); + if (!isEof(pctx)) + throw bad_syntax(); + return result; } } diff --git a/src/tests/test0.cpp b/src/tests/test0.cpp index 2a307f5..9474a23 100644 --- a/src/tests/test0.cpp +++ b/src/tests/test0.cpp @@ -48,6 +48,8 @@ void ftest(int i) { } int main(){ + prettyprint_json(parse_str_flawless("{\"C\":{\"L\":0}}")); + json::JSON A; A[1].asString(); A[0].asInteger();