From 3efee8706467e39e220834b1b625487817d412e5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Sat, 7 Sep 2024 11:44:08 +0200 Subject: [PATCH] ; * src/json.c: refactor: clean out development detritus * src/json.c (enum ParseEndBehavior): Remove. (json_parse): Simplify, moving most code to the callers. (cherry picked from commit 9a1de38528a6a7bc8dcd283d430e2f69ce3fcae4) --- src/json.c | 57 ++++++++++++++++-------------------------------------- 1 file changed, 17 insertions(+), 40 deletions(-) diff --git a/src/json.c b/src/json.c index 41566f8369b..282dca6e8ff 100644 --- a/src/json.c +++ b/src/json.c @@ -1658,43 +1658,10 @@ json_parse_value (struct json_parser *parser, int c) } } -enum ParseEndBehavior - { - PARSEENDBEHAVIOR_CheckForGarbage, - PARSEENDBEHAVIOR_MovePoint - }; - static Lisp_Object -json_parse (struct json_parser *parser, - enum ParseEndBehavior parse_end_behavior) +json_parse (struct json_parser *parser) { - int c = json_skip_whitespace (parser); - - Lisp_Object result = json_parse_value (parser, c); - - switch (parse_end_behavior) - { - case PARSEENDBEHAVIOR_CheckForGarbage: - c = json_skip_whitespace_if_possible (parser); - if (c >= 0) - json_signal_error (parser, Qjson_trailing_content); - break; - case PARSEENDBEHAVIOR_MovePoint: - { - ptrdiff_t byte = (PT_BYTE + parser->input_current - parser->input_begin - + parser->additional_bytes_count); - ptrdiff_t position; - if (NILP (BVAR (current_buffer, enable_multibyte_characters))) - position = byte; - else - position = PT + parser->point_of_current_line + parser->current_column; - - SET_PT_BOTH (position, byte); - break; - } - } - - return result; + return json_parse_value (parser, json_skip_whitespace (parser)); } DEFUN ("json-parse-string", Fjson_parse_string, Sjson_parse_string, 1, MANY, @@ -1738,10 +1705,12 @@ usage: (json-parse-string STRING &rest ARGS) */) const unsigned char *begin = SDATA (string); json_parser_init (&p, conf, begin, begin + SBYTES (string), NULL, NULL); record_unwind_protect_ptr (json_parser_done, &p); + Lisp_Object result = json_parse (&p); - return unbind_to (count, - json_parse (&p, - PARSEENDBEHAVIOR_CheckForGarbage)); + if (json_skip_whitespace_if_possible (&p) >= 0) + json_signal_error (&p, Qjson_trailing_content); + + return unbind_to (count, result); } DEFUN ("json-parse-buffer", Fjson_parse_buffer, Sjson_parse_buffer, @@ -1799,9 +1768,17 @@ usage: (json-parse-buffer &rest args) */) json_parser_init (&p, conf, begin, end, secondary_begin, secondary_end); record_unwind_protect_ptr (json_parser_done, &p); + Lisp_Object result = json_parse (&p); + + ptrdiff_t byte = (PT_BYTE + p.input_current - p.input_begin + + p.additional_bytes_count); + ptrdiff_t position = (NILP (BVAR (current_buffer, + enable_multibyte_characters)) + ? byte + : PT + p.point_of_current_line + p.current_column); + SET_PT_BOTH (position, byte); - return unbind_to (count, - json_parse (&p, PARSEENDBEHAVIOR_MovePoint)); + return unbind_to (count, result); } void -- 2.39.2