InternetLib

encode, decode, et al

URL functions

Types

encode :: [Char] -> [Char]
decode :: [Char] -> [Char]
encodeQuery :: [([Char], [Char])] -> [Char]
decodeQuery :: [Char] -> [([Char], [Char])]

Description

Spaces, and other special characters, are not allowed in URLs, so there is an escape mechanism to represent them.

The function encode converts a string by escaping special characters, returning a string suitable for use in a URL. The function decode undoes the effect of encode

When the contents of a form (here referred to as a query) is submitted to a web server, it is encoded as a sequence of pairs of field names and values in the following way:

  field_1=value_1&...&field_n=value_n

Special characters, like =, & and spaces, occuring in the field names and values, are escaped, as with the function encode.

The functions encodeQuery and decodeQuery convert to and from the above form, applying encode and decode, respectively, to the parts of the query.

Examples

  encode "Sixth Sense, The (1999)" = "Sixth+Sense%2C+The+%281999%29"

deocdeQuery "year=1999&actor=Willis%2C+Bruce" = [("year","1999"),("actor","Willis, Bruce")]

See Also

The type URL.

The Computing dictionary entry for URL.


InternetLib