formEncode

Encodes a Key-Value map into a form URL encoded string.

Writes to the OutputRange an application/x-www-form-urlencoded MIME formatted string, ie. all spaces ' ' are replaced by the '+' character

  1. void formEncode(R dst, T map, char sep)
    void
    formEncode
    (
    R
    T
    )
    (
    auto ref R dst
    ,
    T map
    ,
    char sep = '&'
    )
    if (
    isFormMap!T &&
    isOutputRange!(R, char)
    )
  2. string formEncode(T map, char sep)
  3. string formEncode(T map, char sep)

Parameters

dst R

The destination OutputRange where the resulting string must be written to.

map T

An iterable key-value map iterable with foreach(string key, string value; map).

sep char

A valid form separator, common values are '&' or ';'

Examples

The following example demonstrates the use of formEncode with a json map, the ordering of keys will be preserved in Bson and DictionaryList objects only.

import std.array : Appender;
string[string] map;
map["numbers"] = "123456789";
map["spaces"] = "1 2 3 4 a b c d";

Appender!string app;
app.formEncode(map);
assert(app.data == "spaces=1+2+3+4+a+b+c+d&numbers=123456789" ||
	   app.data == "numbers=123456789&spaces=1+2+3+4+a+b+c+d");

Meta