Next: , Previous: , Up: Top   [Contents][Index]

4 (www url-coding)

The (www url-coding) module provides two procedures for decoding and encoding URL strings for safe transmission according to RFC 1738.

Procedure: url-coding:decode str [u8]

Return a new string made from url-decoding str. Specifically, turn + into space, and hex-encoded %XX strings into their eight-bit characters.

If optional arg u8 is non-#f, return u8vector instead of string, useful for further processing in the case when the desired “character set” is not ISO-8859-1. For example:

(url-coding:decode "%E2%98%A1" #t)
⇒ #u8(226 152 161) ; aka U+2621 CAUTION SIGN in UTF-8
Procedure: url-coding:encode str reserved-chars

Return a new string made from url-encoding str, unconditionally transforming those in reserved-chars, a list of characters to be omitted from the standard (safe) set:

A through Z
a through z
0 through 9
$ - _ . + ! * ' ( ) , ; / ? : @ & =

For example:

(url-coding:encode "/foo/bar/baz" '())
⇒ "/foo/bar/baz"

(url-coding:encode "/foo/bar/baz" '(#\/ #\b))
⇒ "%2ffoo%2f%62ar%2f%62az"