std/uri/form
std/uri/src/form.trb
application/x-www-form-urlencoded, the convention of HTML forms for a query and for a form body, as the WHATWG URL
Standard (section 5) defines it. It is not part of RFC 3986, which leaves a query opaque; that is why the URI types
hold the query as text and read it through these two methods only when asked (docs/design/URI.md section 5).
extend String
extend String
Adds formDecoded to a string, to read it as application/x-www-form-urlencoded.
fn formDecoded
fn formDecoded(): List<(String, String)>
A form read into its pairs, in order: split at &, each part at its first =, + read as a space, escapes
decoded, and the bytes read as UTF-8 with U+FFFD for what is not. Empty parts are skipped and a part without =
has the value "". Nothing fails: this is the standard's parser, which a browser applies to whatever it is handed.
Examples
print "name=Ada+Lovelace&tag=a&tag=b&flag".formDecoded()
extend List<(String, String)>
extend List<(String, String)>
Adds formEncoded to a list of name and value pairs, to write it as application/x-www-form-urlencoded.
fn formEncoded
fn formEncoded(): String
Pairs written as a form: every byte but ASCII letters, digits, *, -, . and _ percent-encoded, a space as
+, = between a name and its value and & between the pairs. This is the standard's serializer, so what a
browser would send for the same fields is what comes out.
Examples
const pairs = [("q", "GrĂ¼ner Weg"), ("page", "2")]
print pairs.formEncoded()