#94 Uri

brian Sat 1 Jul 2006

I checked in sys::Uri - I've got support for component accessors; I'm about half way thru the documentation and test suite. Then I'll be adding support for manipulation methods like join and relativize.

I also implemented support for Uri literals using the back tick, for example http://foo/ will result in a Uri instance as if Uri.parse("http://foo/") was called. However to gain the performance advantage of only parsing the Uri once, I actually implemented them as first class literals beyond just syntax sugar. This means the pod zip will contain a "uris.def" file and there is a new LoadUri opcode. Iterpolation is not supported, neither is any type of backslash escape (since those are illegal URI chars anyways).

Open issues:

  • how much normalization (should scheme always be lowercase)
  • how to deal with escape sequences? what char encoding?
  • support for IRIs?

brian Sun 2 Jul 2006

I finished up the Uri API (at least for this stage of development). It's fully documented with examples and tested. I handled joins via the plus operator, and relativization via the minus operator:

**
** Return a new Uri with the specified Uri appended to this Uri.
**
** Examples:
**  `http://foo/path` + `http://bar/` -> `http://bar/`
**  `http://foo/path?q#f` + `newpath` -> `http://foo/newpath`
**  `http://foo/path/?q#f` + `newpath` -> `http://foo/path/newpath`
**  `a/b/c`  + `d` -> `a/b/d`
**  `a/b/c/` + `d` -> `a/b/c/d`
**  `a/b/c`  + `../../d` -> `d`
**  `a/b/c/` + `../../d` -> `a/d`
**  `a/b/c`  + `../../../d` -> `../d`
**  `a/b/c/` + `../../../d` -> `d`
**
Uri plus(Uri toAppend)

**
** Relativize the specified uri against this uri as a base.
**
** Examples:
**   `http://foo/a/b/c` - `http://foo/a/b/c` -> ``
**   `http://foo/a/b`- `http://foo/a/b/c` -> `c`
**   `http://foo/` - //foo/a/b/c` -> `a/b/c`
**   `/a` - `/a/b/c` ->  `b/c`
**
Uri minus(Uri toRelativize)

Login or Signup to reply.