Type to represent URIs?

Erikvv erik at evanv.nl
Tue Jan 29 03:42:21 UTC 2019


On Monday, 28 January 2019 at 17:53:17 UTC, Victor Porton wrote:
> Which type should I use to represent (absolute) URIs (or URLs)?
>
> Is it OK to use `string` for this, or is there a better option?
>
> I could also use URI class from my library:
> https://github.com/vporton/redland-bindings/blob/dlang/dlang/source/rdf/raptor/uri.d
> https://github.com/vporton/redland-bindings/blob/dlang/dlang/source/rdf/redland/uri.d
>
> but as you see in this library there are two choices for URI 
> class and it's unclear which of the two I would use.

It depends. If you're just taking a string from config or user 
input and passing it to a library, I would just leave it a string.

However, if you are going to manipulate the url, like adding 
query parameters, changing the path, or checking the protocol, I 
would use a URI class for that.

http://code.dlang.org/packages/urld looks good to me.


More information about the Digitalmars-d mailing list