www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - What about Uri class?

reply "Andrea Fontana" <nospam example.com> writes:
What about a Uri class to build/split uri in components?

Reading RFC, there's a regex to split uri:


         string url = 
"http://example.com/path/subpath/?query=val&query2=val#frag";
         enum ctr = 
ctRegex!(r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?");

         auto m = match(url, ctr);
         if (m)
         {
                 writeln("scheme " ~ m.captures[2]);
                 writeln("autority " ~ m.captures[4]);
                 writeln("path " ~ m.captures[5]);
                 writeln("query " ~ m.captures[7]);
                 writeln("fragment " ~ m.captures[9]);
         }

It would be useful to have it on phobos, and adding some method 
to build up uri too. On std.path we have functions for path 
operations...
Mar 24 2012
parent "Nick Sabalausky" <a a.a> writes:
"Andrea Fontana" <nospam example.com> wrote in message 
news:ojmxjzkuimgrtpvedofq forum.dlang.org...
 What about a Uri class to build/split uri in components?

 Reading RFC, there's a regex to split uri:


         string url = 
 "http://example.com/path/subpath/?query=val&query2=val#frag";
         enum ctr = 
 ctRegex!(r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?");

         auto m = match(url, ctr);
         if (m)
         {
                 writeln("scheme " ~ m.captures[2]);
                 writeln("autority " ~ m.captures[4]);
                 writeln("path " ~ m.captures[5]);
                 writeln("query " ~ m.captures[7]);
                 writeln("fragment " ~ m.captures[9]);
         }

 It would be useful to have it on phobos, and adding some method to build 
 up uri too. On std.path we have functions for path operations...

Yea, something like that would be a very good thing to have in Phobos.
Mar 24 2012