Parsing URL, Extracting Authority from the URL string

Andre Pany andre at s-e-a-p.de
Mon May 20 14:56:32 UTC 2019


On Monday, 20 May 2019 at 14:44:50 UTC, Boqsc wrote:
> I wonder if there is a simple way to extract Authority from an 
> URL string.
> What is Authority of URL: 
> https://en.wikipedia.org/wiki/URL#Syntax
>
>
>
> https://dlang.org/phobos/std_path.html
> I was able to gather the filename of URL via std.path package 
> function: baseName.
>
> import std.stdio, std.path;
> void main()
> {
> string url = 
> "https://github.com/BoQsc/notes/archive/master.zip";
>
> // Output: url filename: master.zip
> writeln("url filename: ", url.baseName);
>
> // Output: url path: https://github.com/BoQsc/notes/archive
> writeln("url path: ", url.dirName);
>
>
> }
>
>
>
> However it seems that std.path lacks ability to extract 
> Authority part that URL contains.
>
> https://dlang.org/phobos/std_path.html#rootName
> I tried std.path.rootName, but it didn't return Authority part 
> of URL.
>
> import std.stdio, std.path;
> void main()
> {
> string url = 
> "https://github.com/BoQsc/notes/archive/master.zip";
>
> // Output: url path:
> writeln("url path: ", url.rootName);
> }
>
>
> I'm questioning, if D lang will ever include simple URL parsing 
> into their std Phobos library?

Curl added an api to access the URL parser it itself uses. It 
would say, it is just an pull request away.

For the time being you can e.g. have a look at the package arsd. 
It contains an url parser and is very small without any further 
dependencies.

Kind regards
Andre


More information about the Digitalmars-d-learn mailing list