From dfbe154629cf35e257bb786f26bae83ecbf133cf Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Thu, 3 Mar 2011 17:14:03 +0100 Subject: =?UTF-8?q?Add=20the=20=E2=80=9Curl-param-value=E2=80=9D=20formatt?= =?UTF-8?q?er.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- formatters.lisp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/formatters.lisp b/formatters.lisp index 6d86a98..a3a2129 100644 --- a/formatters.lisp +++ b/formatters.lisp @@ -34,6 +34,22 @@ finally (write-string string out :start position)))))) +(defun escape-for-uri (string) + (with-output-to-string (out) + (map 'list + (lambda (char) + (let ((cnum (char-code char))) + (if (or (<= (char-code #\A) cnum (char-code #\Z)) + (<= (char-code #\a) cnum (char-code #\z)) + (<= (char-code #\0) cnum (char-code #\9)) + (member char + '(#\$ #\- #\_ #\. #\+ #\! #\* #\( #\) #\'))) + (write-char char out) + ;; NOTE: This assumes that (< cnum 256). + (format out "%~2,'0X" cnum)))) + string))) + + (defvar *template-formatters* `(("html" . ,(make-escaper '((#\< . "<") (#\> . "?") @@ -43,4 +59,5 @@ (#\& . "&") (#\' . "'") (#\" . """)))) + ("url-param-value" . escape-for-uri) ("raw" . identity))) -- cgit v1.2.3