Uri class and parser
Mike van Dongen
dlang at mikevandongen.nl
Thu Oct 25 04:24:22 PDT 2012
On Wednesday, 24 October 2012 at 20:36:51 UTC, Adam D. Ruppe
wrote:
> On Wednesday, 24 October 2012 at 19:54:54 UTC, Jacob Carlborg
> wrote:
>> A nitpick, I'm not really an expert on URI's but is "fragment"
>> really the correct name for that I would call the "hash"? That
>> would be "nose" in the example below.
>
> Yes, that's the term in the standard.
>
> http://en.wikipedia.org/wiki/Fragment_identifier
The only reason I used "fragment" was because both the RFC and
the Wikipedia page called it that way. I hate to break protocol ;)
> Cool. It would be nice to have a way to set the query and path
> as an (associative) array as well.
Now it allows you to create/edit an URI. You can do so by using
an array or string, whichever you prefer.
I also added a toString() method and fixed the indentation to 4
spaces, instead of 1 tab.
uri = new Uri();
uri.scheme = "foo";
uri.username = "username";
uri.password = "password";
uri.host = "example.com";
uri.port = 8042;
uri.path = ["over", "there", "index.dtb"];
uri.query = ["type": "animal", "name": "narwhal", "novalue": ""];
uri.fragment = "nose";
assert(uri.toString() ==
"foo://username:password@example.com:8042/over/there/index.dtb?novalue=&name=narwhal&type=animal#nose");
More information about the Digitalmars-d
mailing list