Function: org-link--decode-compound
org-link--decode-compound is a byte-compiled function defined in
ol.el.gz.
Signature
(org-link--decode-compound HEX)
Documentation
Unhexify Unicode hex-chars HEX.
E.g. "%C3%B6" is the German o-Umlaut. Note: this function also decodes single byte encodings like "%E1" (a-acute) if not followed by another "%[A-F0-9]{2}" group.
Source Code
;; Defined in /usr/src/emacs/lisp/org/ol.el.gz
(defun org-link--decode-compound (hex)
"Unhexify Unicode hex-chars HEX.
E.g. \"%C3%B6\" is the German o-Umlaut. Note: this function also
decodes single byte encodings like \"%E1\" (a-acute) if not
followed by another \"%[A-F0-9]{2}\" group."
(save-match-data
(let* ((bytes (cdr (split-string hex "%")))
(ret "")
(eat 0)
(sum 0))
(while bytes
(let* ((val (string-to-number (pop bytes) 16))
(shift-xor
(if (= 0 eat)
(cond
((>= val 252) (cons 6 252))
((>= val 248) (cons 5 248))
((>= val 240) (cons 4 240))
((>= val 224) (cons 3 224))
((>= val 192) (cons 2 192))
(t (cons 0 0)))
(cons 6 128))))
(when (>= val 192) (setq eat (car shift-xor)))
(setq val (logxor val (cdr shift-xor)))
(setq sum (+ (ash sum (car shift-xor)) val))
(when (> eat 0) (setq eat (- eat 1)))
(cond
((= 0 eat) ;multi byte
(setq ret (concat ret (char-to-string sum)))
(setq sum 0))
((not bytes) ; single byte(s)
(setq ret (org-link--decode-single-byte-sequence hex))))))
ret)))