Useful Utilities

This page gives information about useful utilities included in CL-HTTP, for performing translations and other operations frequently needed when programming web sites.

Escaping and unescaping strings for URLs

See: http://en.wikipedia.org/wiki/Percent-encoding

string-escape-special-chars (string &optional start end)

Escapes characters illegal in URLs using %xx notation. For example:

(string-escape-special-chars "Contact http://www.google.com/")
"Contact%20http%3A%2F%2Fwww.google.com%2F"
T

 The second value returned indicates if any characters were escaped.

write-string-escaping-special-chars (string &optional stream start end))

As string-escape-special-chars, but writes the escaped string to a stream.

string-unescape-special-chars (string &optional start end)

Unescapes characters encoded with percent encoding. For example:

(string-unescape-special-chars "Contact%20http%3A%2F%2Fwww.google.com%2F")
"Contact http://www.google.com/"
T
T

The second value returned indicates if any characters were unescaped, and the third value indicates if a new string was returned.

Escaping and unescaping strings for HTML

write-string-quoting-specials (string &optional stream start end)

Writes a string to the stream, encoding the four special characters disallowed in HTML:

><&"

For example:

(write-string-quoting-specials "Write <p>&nbsp;</p>" *standard-output*)
Write &lt;p&gt;&amp;nbsp;&lt;/p&gt;
NIL

Encoding and decoding LISP forms

write-to-armor-plated-string (form)

Encodes a LISP form as a base64-encoded string that can be included in a URL or as the value of a form field. For example:

(write-to-armor-plated-string '(ant bee cat dog))
"KEFOVCBCRUUgQ0FUIERPRyk*"

read-from-armor-plated-string (string)

Encodes a base64-encoded string back into a LISP form. For example:

(read-from-armor-plated-string "KEFOVCBCRUUgQ0FUIERPRyk*")
(ANT BEE CAT DOG)
17

blog comments powered by Disqus