diff options
| author | Mattias EngdegÄrd | 2024-09-07 11:44:08 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2024-09-09 10:30:02 +0200 |
| commit | 9a1de38528a6a7bc8dcd283d430e2f69ce3fcae4 (patch) | |
| tree | d8fe7e8c00ff36b3a7b5e5ee32da6fe0ce30fa71 /src | |
| parent | 4073c624376148d469a27a7c487a9b2f49d5352a (diff) | |
| download | emacs-9a1de38528a6a7bc8dcd283d430e2f69ce3fcae4.tar.gz emacs-9a1de38528a6a7bc8dcd283d430e2f69ce3fcae4.zip | |
; * src/json.c: refactor: clean out development detritus
* src/json.c (enum ParseEndBehavior): Remove.
(json_parse): Simplify, moving most code to the callers.
Diffstat (limited to 'src')
| -rw-r--r-- | src/json.c | 57 |
1 files 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) | |||
| 1668 | } | 1668 | } |
| 1669 | } | 1669 | } |
| 1670 | 1670 | ||
| 1671 | enum ParseEndBehavior | ||
| 1672 | { | ||
| 1673 | PARSEENDBEHAVIOR_CheckForGarbage, | ||
| 1674 | PARSEENDBEHAVIOR_MovePoint | ||
| 1675 | }; | ||
| 1676 | |||
| 1677 | static Lisp_Object | 1671 | static Lisp_Object |
| 1678 | json_parse (struct json_parser *parser, | 1672 | json_parse (struct json_parser *parser) |
| 1679 | enum ParseEndBehavior parse_end_behavior) | ||
| 1680 | { | 1673 | { |
| 1681 | int c = json_skip_whitespace (parser); | 1674 | return json_parse_value (parser, json_skip_whitespace (parser)); |
| 1682 | |||
| 1683 | Lisp_Object result = json_parse_value (parser, c); | ||
| 1684 | |||
| 1685 | switch (parse_end_behavior) | ||
| 1686 | { | ||
| 1687 | case PARSEENDBEHAVIOR_CheckForGarbage: | ||
| 1688 | c = json_skip_whitespace_if_possible (parser); | ||
| 1689 | if (c >= 0) | ||
| 1690 | json_signal_error (parser, Qjson_trailing_content); | ||
| 1691 | break; | ||
| 1692 | case PARSEENDBEHAVIOR_MovePoint: | ||
| 1693 | { | ||
| 1694 | ptrdiff_t byte = (PT_BYTE + parser->input_current - parser->input_begin | ||
| 1695 | + parser->additional_bytes_count); | ||
| 1696 | ptrdiff_t position; | ||
| 1697 | if (NILP (BVAR (current_buffer, enable_multibyte_characters))) | ||
| 1698 | position = byte; | ||
| 1699 | else | ||
| 1700 | position = PT + parser->point_of_current_line + parser->current_column; | ||
| 1701 | |||
| 1702 | SET_PT_BOTH (position, byte); | ||
| 1703 | break; | ||
| 1704 | } | ||
| 1705 | } | ||
| 1706 | |||
| 1707 | return result; | ||
| 1708 | } | 1675 | } |
| 1709 | 1676 | ||
| 1710 | DEFUN ("json-parse-string", Fjson_parse_string, Sjson_parse_string, 1, MANY, | 1677 | DEFUN ("json-parse-string", Fjson_parse_string, Sjson_parse_string, 1, MANY, |
| @@ -1748,10 +1715,12 @@ usage: (json-parse-string STRING &rest ARGS) */) | |||
| 1748 | const unsigned char *begin = SDATA (string); | 1715 | const unsigned char *begin = SDATA (string); |
| 1749 | json_parser_init (&p, conf, begin, begin + SBYTES (string), NULL, NULL); | 1716 | json_parser_init (&p, conf, begin, begin + SBYTES (string), NULL, NULL); |
| 1750 | record_unwind_protect_ptr (json_parser_done, &p); | 1717 | record_unwind_protect_ptr (json_parser_done, &p); |
| 1718 | Lisp_Object result = json_parse (&p); | ||
| 1751 | 1719 | ||
| 1752 | return unbind_to (count, | 1720 | if (json_skip_whitespace_if_possible (&p) >= 0) |
| 1753 | json_parse (&p, | 1721 | json_signal_error (&p, Qjson_trailing_content); |
| 1754 | PARSEENDBEHAVIOR_CheckForGarbage)); | 1722 | |
| 1723 | return unbind_to (count, result); | ||
| 1755 | } | 1724 | } |
| 1756 | 1725 | ||
| 1757 | DEFUN ("json-parse-buffer", Fjson_parse_buffer, Sjson_parse_buffer, | 1726 | DEFUN ("json-parse-buffer", Fjson_parse_buffer, Sjson_parse_buffer, |
| @@ -1809,9 +1778,17 @@ usage: (json-parse-buffer &rest args) */) | |||
| 1809 | json_parser_init (&p, conf, begin, end, secondary_begin, | 1778 | json_parser_init (&p, conf, begin, end, secondary_begin, |
| 1810 | secondary_end); | 1779 | secondary_end); |
| 1811 | record_unwind_protect_ptr (json_parser_done, &p); | 1780 | record_unwind_protect_ptr (json_parser_done, &p); |
| 1781 | Lisp_Object result = json_parse (&p); | ||
| 1782 | |||
| 1783 | ptrdiff_t byte = (PT_BYTE + p.input_current - p.input_begin | ||
| 1784 | + p.additional_bytes_count); | ||
| 1785 | ptrdiff_t position = (NILP (BVAR (current_buffer, | ||
| 1786 | enable_multibyte_characters)) | ||
| 1787 | ? byte | ||
| 1788 | : PT + p.point_of_current_line + p.current_column); | ||
| 1789 | SET_PT_BOTH (position, byte); | ||
| 1812 | 1790 | ||
| 1813 | return unbind_to (count, | 1791 | return unbind_to (count, result); |
| 1814 | json_parse (&p, PARSEENDBEHAVIOR_MovePoint)); | ||
| 1815 | } | 1792 | } |
| 1816 | 1793 | ||
| 1817 | void | 1794 | void |