; * src/json.c: refactor: clean out development detritus
* src/json.c (enum ParseEndBehavior): Remove. (json_parse): Simplify, moving most code to the callers.
This commit is contained in:
parent
4073c62437
commit
9a1de38528
1 changed files with 17 additions and 40 deletions
57
src/json.c
57
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);
|
||||
|
||||
return unbind_to (count,
|
||||
json_parse (&p, PARSEENDBEHAVIOR_MovePoint));
|
||||
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, result);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Add table
Reference in a new issue