[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 9a1de38528a 1/4: ; * src/json.c: refactor: clean out development
From: |
Mattias Engdegård |
Subject: |
master 9a1de38528a 1/4: ; * src/json.c: refactor: clean out development detritus |
Date: |
Mon, 9 Sep 2024 04:42:28 -0400 (EDT) |
branch: master
commit 9a1de38528a6a7bc8dcd283d430e2f69ce3fcae4
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>
; * src/json.c: refactor: clean out development detritus
* src/json.c (enum ParseEndBehavior): Remove.
(json_parse): Simplify, moving most code to the callers.
---
src/json.c | 57 +++++++++++++++++----------------------------------------
1 file changed, 17 insertions(+), 40 deletions(-)
diff --git a/src/json.c b/src/json.c
index 21066d21328..eb2fa0472c8 100644
--- a/src/json.c
+++ b/src/json.c
@@ -1668,43 +1668,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,
@@ -1748,10 +1715,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,
@@ -1809,9 +1778,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