URL encode a single character. (slow, logically nice version).
(vl-url-encode-char x) → encoding
See vl-fast-url-encode-char for an faster, array-lookup alternative.
Function:
(defun vl-url-encode-char (x) (declare (xargs :guard (characterp x))) (let ((__function__ 'vl-url-encode-char)) (declare (ignorable __function__)) (let ((x (char-fix x))) (if (or (and (char<= #\A x) (char<= x #\Z)) (and (char<= #\a x) (char<= x #\z)) (and (char<= #\0 x) (char<= x #\9)) (member x '(#\- #\_ #\. #\~))) (list x) (let* ((hex-code (explode-atom (char-code x) 16)) (hex-code (if (eql (len hex-code) 1) (cons #\0 hex-code) hex-code))) (cons #\% hex-code))))))
Theorem:
(defthm character-listp-of-vl-url-encode-char (b* ((encoding (vl-url-encode-char x))) (character-listp encoding)) :rule-classes :rewrite)
Theorem:
(defthm vl-url-encode-char-of-char-fix-x (equal (vl-url-encode-char (char-fix x)) (vl-url-encode-char x)))
Theorem:
(defthm vl-url-encode-char-chareqv-congruence-on-x (implies (chareqv x x-equiv) (equal (vl-url-encode-char x) (vl-url-encode-char x-equiv))) :rule-classes :congruence)