Thread overview | ||||||
---|---|---|---|---|---|---|
|
May 20, 2019 Parsing URL, Extracting Authority from the URL string | ||||
---|---|---|---|---|
| ||||
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? |
May 20, 2019 Re: Parsing URL, Extracting Authority from the URL string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Boqsc | 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
|
May 20, 2019 Re: Parsing URL, Extracting Authority from the URL string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Boqsc | On Monday, 20 May 2019 at 14:44:50 UTC, Boqsc wrote: > I'm questioning, if D lang will ever include simple URL parsing into their std Phobos library? idk about phobos, but I have one of these in my web server library http://dpldocs.info/experimental-docs/arsd.cgi.Uri.html (also copy/pasted to the http client lib) http://dpldocs.info/experimental-docs/arsd.http2.Uri.html you can copy/paste it too if you like. This package appears good to me too, with decent docs and sane looking tests, at least for data extraction (mine was written more for the relative link handling) http://code.dlang.org/packages/urld |
May 20, 2019 Re: Parsing URL, Extracting Authority from the URL string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Monday, 20 May 2019 at 14:57:57 UTC, Adam D. Ruppe wrote: > idk about phobos, but I have one of these in my web server library git hub link https://github.com/adamdruppe/arsd or dub link http://code.dlang.org/packages/arsd-official |
Copyright © 1999-2021 by the D Language Foundation