Function: majutsu-diff--read-git-quoted-token
majutsu-diff--read-git-quoted-token is a natively compiled function
defined in majutsu-diff.el.
Signature
(majutsu-diff--read-git-quoted-token TOKEN)
Documentation
Decode one C-quoted Git path at the start of TOKEN.
Return (VALUE . END), where END is the first position after the closing quote, or nil for malformed input.
Source Code
;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-diff.el
(defun majutsu-diff--read-git-quoted-token (token)
"Decode one C-quoted Git path at the start of TOKEN.
Return (VALUE . END), where END is the first position after the closing quote,
or nil for malformed input."
(when (string-prefix-p "\"" token)
(catch 'done
(let ((index 1)
bytes)
(cl-labels
((push-char
(char)
(dolist (byte (string-to-list
(encode-coding-string (string char) 'utf-8 t)))
(push byte bytes))))
(while (< index (length token))
(let ((char (aref token index)))
(setq index (1+ index))
(cond
((= char ?\")
(let ((raw (apply #'unibyte-string (nreverse bytes))))
(throw 'done
(cons (decode-coding-string raw 'utf-8 t) index))))
((/= char ?\\)
(push-char char))
((>= index (length token))
(throw 'done nil))
(t
(let ((escaped (aref token index)))
(cond
((and (>= escaped ?0) (<= escaped ?7))
(let ((start index)
(count 0))
(while (and (< index (length token))
(< count 3)
(>= (aref token index) ?0)
(<= (aref token index) ?7))
(setq index (1+ index)
count (1+ count)))
(let ((byte (string-to-number
(substring token start index) 8)))
(when (> byte 255)
(throw 'done nil))
(push byte bytes))))
(t
(setq index (1+ index))
(let ((byte (cdr (assq escaped
'((?a . 7) (?b . 8) (?t . 9)
(?n . 10) (?v . 11) (?f . 12)
(?r . 13) (?\" . 34) (?\\ . 92))))))
(unless byte
(throw 'done nil))
(push byte bytes))))))))))
nil))))