(defsubst json-peek ()
"Return the character at point."
- (or (char-after (point)) :json-eof))
+ (following-char))
(defsubst json-pop ()
"Advance past the character at point, returning it."
(let ((char (json-peek)))
- (if (eq char :json-eof)
+ (if (zerop char)
(signal 'json-end-of-file nil)
(json-advance)
char)))
(special (cdr special))
((not (eq char ?u)) char)
;; Special-case UTF-16 surrogate pairs,
- ;; cf. https://tools.ietf.org/html/rfc7159#section-7. Note that
+ ;; cf. <https://tools.ietf.org/html/rfc7159#section-7>. Note that
;; this clause overlaps with the next one and therefore has to
;; come first.
((looking-at
(let ((characters '())
(char (json-peek)))
(while (not (= char ?\"))
+ (when (< char 32)
+ (signal 'json-string-format (list (prin1-char char))))
(push (if (= char ?\\)
(json-read-escaped-char)
(json-pop))
Advances point just past JSON object."
(json-skip-whitespace)
(let ((char (json-peek)))
- (if (not (eq char :json-eof))
- (let ((record (cdr (assq char json-readtable))))
- (if (functionp (car record))
- (apply (car record) (cdr record))
- (signal 'json-readtable-error record)))
- (signal 'json-end-of-file nil))))
+ (if (zerop char)
+ (signal 'json-end-of-file nil)
+ (let ((record (cdr (assq char json-readtable))))
+ (if (functionp (car record))
+ (apply (car record) (cdr record))
+ (signal 'json-readtable-error record))))))
;; Syntactic sugar for the reader
(ert-deftest test-json-peek ()
(json-tests--with-temp-buffer ""
- (should (eq (json-peek) :json-eof)))
+ (should (zerop (json-peek))))
(json-tests--with-temp-buffer "{ \"a\": 1 }"
(should (equal (json-peek) ?{))))
(should (equal (json-read-escaped-char) ?\"))))
(ert-deftest test-json-read-string ()
+ (json-tests--with-temp-buffer "\"formfeed\f\""
+ (should-error (json-read-string) :type 'json-string-format))
(json-tests--with-temp-buffer "\"foo \\\"bar\\\"\""
(should (equal (json-read-string) "foo \"bar\"")))
(json-tests--with-temp-buffer "\"abcαβγ\""