259. URL

Manipulate and Parse URLs

259.1. Summary of Module Globals

List of Global Functions

  • Build - Build URL from tokens as parsed with Parse

  • Check - Check URL

  • EscapeString - Escape reserved characters in string used as a part of URL (e.g. '%' => '%25', '@' => '%40'...)

  • FormatURL - Format URL - truncate the middle part of the directory to fit to the requested lenght.

  • Parse - Tokenize URL

  • UnEscapeString - Escape reserved characters in string used as a part of URL (e.g. '%' => '%25', '@' => '%40'...)

List of Global Variables

  • transform_map_filename - Transform map used for (un)escaping characters in file location part of an URL. It doesn't contain '%' because this character must be used in a particular order (the first or the last) during processing

  • transform_map_passwd - Transform map used for (un)escaping characters in username/password part of an URL. It doesn't contain '%' because this character must be used in a particular order (the first or the last) during processing

  • transform_map_query - Transform map used for (un)escaping characters in query part of a URL. It doesn't contain '%' because this character must be used in a particular order (the first or the last) during processing

259.2. Global Functions

259.2.1. Build

Build URL from tokens as parsed with Parse

Function parameters

  • map tokens

Return value

  • string - url, empty string if invalid data is used to build the url.

259.2.2. Check

Check URL

Function parameters

  • string url

Return value

  • boolean - true if correct

259.2.3. EscapeString

Escape reserved characters in string used as a part of URL (e.g. '%' => '%25', '@' => '%40'...)

Function parameters

  • string in

  • map<string,string> transform

Return value

  • string - escaped string

259.2.4. FormatURL

Format URL - truncate the middle part of the directory to fit to the requested lenght.

Function parameters

  • map tokens

  • integer len

Return value

  • string - Truncated URL

Example 77. 

 FormatURL("http://download.opensuse.org/very/log/path/which/will/be/truncated/target_file", 45)
&nbsp;&nbsp;&nbsp;&nbsp;-> "http://download.opensuse.org/.../target_file"
 FormatURL("http://download.opensuse.org/very/log/path/which/will/be/truncated/target_file", 60)
&nbsp;&nbsp;&nbsp;&nbsp;-> "http://download.opensuse.org/very/.../be/truncated/target_file"

259.2.5. Parse

Tokenize URL

Function parameters

  • string url

Return value

  • map - URL split to tokens

Example 78. 

 Parse("http://name:pass@www.suse.cz:80/path/index.html?question#part") ->
     $[
         "scheme"  : "http",
         "host"    : "www.suse.cz"
         "port"    : "80",
         "path"    : /path/index.html",
         "user"    : "name",
         "pass"    : "pass",
         "query"   : "question",
         "fragment": "part"
     ]

259.2.6. UnEscapeString

Escape reserved characters in string used as a part of URL (e.g. '%' => '%25', '@' => '%40'...)

Function parameters

  • string in

  • map<string,string> transform

Return value

  • string - escaped string

259.3. Global Variables

259.3.1. transform_map_filename

Transform map used for (un)escaping characters in file location part of an URL. It doesn't contain '%' because this character must be used in a particular order (the first or the last) during processing

259.3.2. transform_map_passwd

Transform map used for (un)escaping characters in username/password part of an URL. It doesn't contain '%' because this character must be used in a particular order (the first or the last) during processing

259.3.3. transform_map_query

Transform map used for (un)escaping characters in query part of a URL. It doesn't contain '%' because this character must be used in a particular order (the first or the last) during processing

259.4. Module Requirements

259.4.1. Module Imports

  • Hostname
  • IP
  • String

259.4.2. Module Includes