include "uris.m"; uris := load URIs URIs->PATH; URI: import uris; URI: adt { scheme: string; userinfo: string; # authority, part I host: string; # authority, part II port: string; # authority, part III path: string; # starts with / if absolute query: string; # includes ? if not nil fragment: string; # includes # if not nil parse: fn(s: string): ref URI; text: fn(u: self ref URI): string; addbase: fn(base: self ref URI, rel: ref URI): ref URI; authority: fn(u: self ref URI): string; copy: fn(u: self ref URI): ref URI; eq: fn(u: self ref URI, v: ref URI): int; hasauthority: fn(u: self ref URI): int; isabsolute: fn(u: self ref URI): int; nodots: fn(u: self ref URI): ref URI; userpw: fn(u: self ref URI): (string, string); }; init: fn(); dec: fn(s: string): string; enc: fn(s: string, safe: string): string;
where each component is optional, and can have scheme-specific substructure. For instance, in the ftp, http schemes, and perhaps others, the authority component has the further syntax:
The set of characters allowed in most components is also scheme-specific, as is their interpretation, and indeed the interpretation of the component itself.
Init must be called before any other operation in the module.
URI represents a parse of a URI into its components, where the authority has been further split into the scheme-specific but common triple of userinfo, host and port. (The function URI.authority will reproduce the original authority component if required.) The query field starts with the `?' character that introduces the query component, so that an empty query is represented by the string "?", and the absence of a query component is represented by a nil value. The fragment field is handled in a similar way with its delimiting `#'. The fields representing the other components do not include the delimiters in the syntax, and all but query have percent-encoded characters decoded. (The query string is an exception because the set of characters to escape is application-specific. See below for decoding and encoding functions.) URI provides the following operations:
A reserved or otherwise special character that appears in a URI component must be encoded using a sequence of one or more strings of the form %xx where xx is the hexadecimal value of one byte of the character. A string s containing such encodings can be decoded by the function dec. A string s can be encoded by enc, where the parameter safe lists the characters that need not be escaped (where safe may be nil or empty). These functions are normally only needed to decode and encode the values of URI.query, because URI.parse and URI.text above decode and encode the other fields.
W3C-URIS(2 ) | Rev: Thu Feb 15 14:43:26 GMT 2007 |