Efficiently way to URL encode a string, in reverse order, without exploding it.
This has such a nice logical definition that we just leave it enabled.
Function:
(defun url-encode-string-aux (x n xl acc) (declare (xargs :guard (and (stringp x) (natp n) (eql xl (length x))))) (declare (xargs :guard (<= n xl))) (let ((acl2::__function__ 'url-encode-string-aux)) (declare (ignorable acl2::__function__)) (mbe :logic (url-encode-chars-aux (nthcdr n (explode x)) acc) :exec (b* (((when (mbe :logic (zp (- (nfix xl) (nfix n))) :exec (eql n xl))) acc) (char (char x n)) (encoding (fast-url-encode-char char)) (acc (revappend encoding acc))) (url-encode-string-aux x (+ 1 (lnfix n)) xl acc)))))