Function: UNESCAPE-AS-URI

Source

(defun unescape-as-uri (string &optional (external-format :iso-8859-1))
  (let* ((length (- (length string)
                    (* 2 (count #\% string :test #'char=))))
         (result (make-array length :element-type '(unsigned-byte 8))))
    (loop
       for index1 upfrom 0
       for index2 upfrom 0
       while (< index1 (length string))
       do (setf (aref result index2)
                (case (aref string index1)
                  (#\% (+ (ash (digit-char-p (aref string (incf index1)) 16) 4)
                          (digit-char-p (aref string (incf index1)) 16)))
                  (#\+ #.(char-code #\space))
                  (t (char-code (aref string index1))))))
    (octets-to-string result external-format)))
Source Context