www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to split strings into AA using phobos

reply Arun Chandrasekaran <aruncxy gmail.com> writes:
A typical example would be to split the HTTP query string into an 
AA.

vibe.d has req.queryString, but no convenient wrapper to access 
it as an AA.

http://localhost/hello?name=abc&id=123

I've got this far.

         auto arr = req.queryString.splitter('&').map!(a => 
a.splitter('='));

Thanks
Dec 11 2018
next sibling parent John Chapman <johnch_atms hotmail.com> writes:
On Tuesday, 11 December 2018 at 08:20:32 UTC, Arun Chandrasekaran 
wrote:
 A typical example would be to split the HTTP query string into 
 an AA.

 vibe.d has req.queryString, but no convenient wrapper to access 
 it as an AA.

 http://localhost/hello?name=abc&id=123

 I've got this far.

         auto arr = req.queryString.splitter('&').map!(a => 
 a.splitter('='));

 Thanks
req.queryString[req.queryString.indexOf('?') + 1 .. $] .splitter('&') .map!(a => a.splitter('=')) .map!(a => tuple(a.front, a.back)) .assocArray
Dec 11 2018
prev sibling next sibling parent reply Andre Pany <andre s-e-a-p.de> writes:
On Tuesday, 11 December 2018 at 08:20:32 UTC, Arun Chandrasekaran 
wrote:
 A typical example would be to split the HTTP query string into 
 an AA.

 vibe.d has req.queryString, but no convenient wrapper to access 
 it as an AA.

 http://localhost/hello?name=abc&id=123

 I've got this far.

         auto arr = req.queryString.splitter('&').map!(a => 
 a.splitter('='));

 Thanks
I am not 100% sure but I think query parameters names can occur multiple times in query string. Therefore you need an associative array with string as key and string[] array as value. By using associative array you loose the order of the parameters. Whether this is important for query parameters I do not know. Kind regards Andre
Dec 11 2018
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Tuesday, 11 December 2018 at 18:46:27 UTC, Andre Pany wrote:
 I am not 100% sure but I think query parameters names can occur 
 multiple times in query string.
Yes, that's right.
Dec 11 2018
prev sibling parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 12/11/18 3:20 AM, Arun Chandrasekaran wrote:
 A typical example would be to split the HTTP query string into an AA.
 
 vibe.d has req.queryString, but no convenient wrapper to access it as an 
 AA.
Yeah it does: http://vibed.org/api/vibe.http.server/HTTPServerRequest.query -Steve
Dec 11 2018