URL encode a single character. (slow, logically nice version).
(url-encode-char x) → encoding
See fast-url-encode-char for an faster, array-lookup alternative.
Function:
(defun url-encode-char (x) (declare (xargs :guard (characterp x))) (let ((acl2::__function__ 'url-encode-char)) (declare (ignorable acl2::__function__)) (b* ((x (char-fix x)) ((when (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)) (hex-code (nat-to-hex-chars (char-code x))) (hex-code (if (eql (len hex-code) 1) (cons #\0 hex-code) hex-code))) (cons #\% hex-code))))
Theorem:
(defthm character-listp-of-url-encode-char (b* ((encoding (url-encode-char x))) (character-listp encoding)) :rule-classes :rewrite)
Theorem:
(defthm url-encode-char-of-char-fix-x (equal (url-encode-char (char-fix x)) (url-encode-char x)))
Theorem:
(defthm url-encode-char-chareqv-congruence-on-x (implies (chareqv x x-equiv) (equal (url-encode-char x) (url-encode-char x-equiv))) :rule-classes :congruence)