Module Url
The Url module performs a number of useful operations on URL strings. For example, it is sometimes useful to break up a URL into its constituent parts, modify some of them, and glue the parts back together again. In the same manner, query strings (the part of a URL that follows the question mark) also need to be manipulated.
For example, given the URL (a typical AltaVista query)
http://www.altavista.digital.com/cgi-bin/query
?pg=q&kl=XX&q=%2Bjava+%2Bcoffee
the Split function will return an object as follows:
[.
query = "?pg=q&kl=XX&q=%2Bjava+%2Bcoffee",
path = "/cgi-bin/query",
host = "www.altavista.digital.com",
ref = "",
scheme = "http"
.]
Applying the
SplitQuery function to the query field of this object will return the following object:
[. kl = "XX", pg = "q", q = "+java +coffee" .]
Behind the scenes, decoding the query string involves calls to the
Decode function to remove the character encodings (eg. %@B and so on).
The Glue and
GlueQuery functions will glue those objects back together again. The field names generated by the Split function are summarized in
See URL constituents
. Note that the current implementation can process only the http, ftp, and file protocol schemes.
Module Url
|
Function
|
Description
|
|
Decode(s: string): string
|
Decodes a string in the MIME type encoding "x-www-form-urlencoded". The complementary function is called Encode.
|
|
Encode(s: string): string
|
Encodes a string in the MIME type encoding "x-www-form-urlencoded" (which is generally used to encode input form parameters). The complementary function is called Decode.
|
|
Glue(obj: object): string
|
Takes the constituent parts of a URL (as broken up by Split), and glues them together to form a URL again.
|
|
GlueQuery(obj: object): string
|
Given an object constructed from SplitQuery, GlueQuery returns the original query string again.
|
|
Resolve(base: string, rel: string): string
|
Given the base URL base and the relative URL rel, return the resolved URL.
|
|
Split(url: string): object
|
Splits a URL into its constituent parts (like scheme, host, path, query etc.). Each part becomes a field of the object returned.
|
|
SplitQuery(query: string): object
|
Splits a query string into its constituent parts. Each part becomes a field of the object returned. Query strings typically follow the ? in URLs.
|
URL constituents
|
Field name
|
Used in
schemes
|
Description
|
|
scheme
|
All
|
http, ftp, file, etc.
|
|
host
|
http, ftp, file
|
Host name.
|
|
port
|
http, ftp
|
TCP/IP connection port.
|
|
path
|
http, ftp, file
|
Full path name of the addressed resource.
|
|
query
|
http
|
Query string (after '?' in URL)
|
|
ref
|
http, file
|
Anchor reference string (after '#' in URL).
|
|
user
|
ftp
|
Login user name.
|
|
password
|
ftp
|
Login password.
|
|
type
|
ftp
|
File transfer type 'a', 'i', 'd'.
|
|
url
|
Unknown schemes
|
Contains the complete URL because no constituents could be extracted (because the scheme is unknown).
|
Up Previous Next