Finish trashinfo.lisp
This commit is contained in:
@ -11,7 +11,9 @@
|
||||
(or (and (>= code (char-code #\a))
|
||||
(<= code (char-code #\z)))
|
||||
(and (>= code (char-code #\A))
|
||||
(<= code (char-code #\Z)))))))
|
||||
(<= code (char-code #\Z)))
|
||||
(and (>= code (char-code #\0))
|
||||
(<= code (char-code #\9)))))))
|
||||
|
||||
(deftype utf-8-code-point ()
|
||||
'(integer 0 #x10FFFF))
|
||||
@ -73,17 +75,26 @@ represent."
|
||||
;; 1 byte
|
||||
(t part1)))))
|
||||
|
||||
(declaim (ftype (function (character) string) escape-char-for-url))
|
||||
(defun escape-char-for-url (char)
|
||||
(declaim (ftype (function (character &key (:safe-chars list)) list)
|
||||
escape-char-for-url))
|
||||
(defun escape-char-for-url (char &key safe-chars)
|
||||
"Escape CHAR such that it is safe to include in a URL."
|
||||
(if (url-unreserved-character-p char)
|
||||
(string char)
|
||||
(format nil "~{%~X~}" (utf-8-encode-char char))))
|
||||
(if (or (url-unreserved-character-p char) (member char safe-chars
|
||||
:test #'eql))
|
||||
(list char)
|
||||
(coerce (format nil "~{%~X~}" (utf-8-encode-char char)) 'list)))
|
||||
|
||||
(declaim (ftype (function (string) string) url-encode))
|
||||
(defun url-encode (string)
|
||||
"URL encode (percent escape) STRING."
|
||||
(format nil "~{~A~}" (map 'list 'escape-char-for-url string)))
|
||||
(declaim (ftype (function (string &key (:start integer) (:end integer)
|
||||
(:safe-chars list))
|
||||
string)
|
||||
url-encode))
|
||||
(defun url-encode (string &key (start 0) (end (length string)) safe-chars)
|
||||
"URL encode (percent escape) STRING. SAFE-CHARS is a list of characters that
|
||||
should not be encoded."
|
||||
(coerce (loop for i upfrom start below end
|
||||
for char = (aref string i)
|
||||
append (escape-char-for-url char :safe-chars safe-chars))
|
||||
'string))
|
||||
|
||||
(define-condition url-decode-error (error)
|
||||
((string :accessor url-decode-error-string
|
||||
|
Reference in New Issue
Block a user