Unit CastleURLUtils

DescriptionUsesClasses, Interfaces, Objects and RecordsFunctions and ProceduresTypesConstantsVariables

Description

URL utilities. Not much for now, will be much more when handling URLs in VRML engine will be really implemented.

Overview

Functions and Procedures

procedure URLExtractAnchor(var URL: string; out Anchor: string);
function RawUrlDecode(const S: string): string;
function UrlProtocol(const S: string): string;
function UrlProtocolIs(const S: string; const Protocol: string; out Colon: Integer): boolean;
function UrlDeleteProtocol(const S: string): string;
function CombineUrls(Base, Relative: string): string;

Description

Functions and Procedures

procedure URLExtractAnchor(var URL: string; out Anchor: string);

Extracts #anchor from URL. On input, URL contains full URL. On output, Anchor is removed from URL and saved in Anchor. If no #anchor existed, Anchor is set to ''.

function RawUrlDecode(const S: string): string;

Replace all sequences like %xx with their actual 8-bit characters.

The intention is that this is similar to PHP function with the same name.

To account for badly encoded strings, invalid encoded URLs do not raise an error — they are only reported to OnWarning. So you can simply ignore them, or write a warning about them for user. This is done because often you will use this with URLs provided by the user, read from some file etc., so you can't be sure whether they are correctly encoded, and raising error unconditionally is not OK. (Considering the number of bad HTML pages on WWW.)

The cases of badly encoded strings are:

  • "%xx" sequence ends unexpectedly at the end of the string. That is, string ends with "%" or "%x". In this case we simply keep "%" or "%x" in resulting string.

  • "xx" in "%xx" sequence is not a valid hexadecimal number. In this case we also simply keep "%xx" in resulting string.

function UrlProtocol(const S: string): string;
 
function UrlProtocolIs(const S: string; const Protocol: string; out Colon: Integer): boolean;

Check does URL contain given Protocol. This is equivalent to checking UrlProtocol(S) = Protocol, ignoring case, although may be a little faster. Given Protocol string cannot contain ":" character.

function UrlDeleteProtocol(const S: string): string;
 
function CombineUrls(Base, Relative: string): string;

Combine base URL with relative, just like CombinePaths does for file paths.

TODO: this is a dummy implementation for now, that basically calls CombinePaths, however it allows the Base or Relative to start with 'file://' prefix (but result will not contain this prefix). This allows most places in our engine (that in the future should deal with URLs) for now just work with local file paths.


Generated by PasDoc 0.12.1 on 2013-02-04 20:26:52