Convert special characters into
(json-encode-weird-char code acc) → new-acc
This lets us properly encode weird things like control characters.
BOZO we could use more readable encoding like
Function:
(defun json-encode-weird-char (code acc) (declare (type (unsigned-byte 8) code)) (let ((__function__ 'json-encode-weird-char)) (declare (ignorable __function__)) (b* ((lo (logand code 15)) (hi (logand (ash code -4) 15)) (acc (cons #\\ acc)) (acc (cons #\u acc)) (acc (cons #\0 acc)) (acc (cons #\0 acc)) (acc (cons (digit-to-char hi) acc)) (acc (cons (digit-to-char lo) acc))) acc)))
Theorem:
(defthm character-listp-of-json-encode-weird-char (implies (character-listp acc) (b* ((new-acc (json-encode-weird-char code acc))) (character-listp new-acc))) :rule-classes :rewrite)