Tcllib URI

uri is a Tcllib module for parsing and manipulating URIs.

Documentation

official reference
official reference , development version

Description

uri::split breaks a URI up into its component parts.

The parts identified depend on the schemes supported. For instance, for ftp, the pieces identified are

  • host
  • path
  • port
  • passwd
  • scheme
  • type
  • user

The file protocol is supported

The data protocol is not yet supported.

LV: What does "doesn't yet support" mean?

AK: That the code does not know to handle such urls (split/join). There are no regexp patterns either.

LV: but I see this behavior with tcl8.4 and tcllib 1.0:

% package require uri
1.0
% set name "file://home/lwv26/myfile.txt"
file://home/lwv26/myfile.txt
% uri::split $name
path /lwv26/myfile.txt scheme file host home

So it LOOKS like file is supported.

VFS handlers

The new Tcl 8.4a4 VFS layer by Vince Darley simplifies this work. See the tclvfs extension for example code which opens http, ftp, zip, and more - using the "blah:..." notation.

Issue: Canonicalize

HaO 2013-05-03 I tried to use 'uri::canonicalize' to implement a smart url completer, e.g. to say transform "test.de" to "http://test.de/ ".

% package require uri
1.2.2
% uri::canonicalize test.de
http:///test.de 

So there are 3 slashes instead of two and no trailing slash. This is not what I intended.

The reason is, that 'uri::canonicalize' internally uses 'uri::split' and 'uri::join'' and the first interprets the given data as a path and not as a host:

% ::uri::split test.de
fragment {} port {} path test.de scheme http host {} query {}

Changelog

AK: The urn handler was added to tcllib after the 1.1.0 release