diff options
| author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2011-03-03 17:14:03 +0100 | 
|---|---|---|
| committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2011-03-03 17:14:03 +0100 | 
| commit | dfbe154629cf35e257bb786f26bae83ecbf133cf (patch) | |
| tree | 4f42c22a45f4c8c3b7ee77dd00e61cec774a8d5e | |
| parent | 415bb34ffbf3e888972025dc7aada6bdf19861e1 (diff) | |
Add the “url-param-value” formatter.
| -rw-r--r-- | formatters.lisp | 17 | 
1 files changed, 17 insertions, 0 deletions
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)))  | 
