Thread overview
How to split strings into AA using phobos
Dec 11, 2018
John Chapman
Dec 11, 2018
Andre Pany
Dec 11, 2018
Adam D. Ruppe
December 11, 2018
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
December 11, 2018
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
December 11, 2018
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
December 11, 2018
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.
December 11, 2018
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