QueryOptions
#struct QueryOptionsThe encoding options.
| Name | Type | Description |
|---|---|---|
space_as_plus | bool = true | Form style, true by default: a space is written as + and a + is read as a space. When false, %20 is written and a + is read as a plus sign. |
import encoding.query
func main throw:
text := "q=hello&page=2&tag=a&tag=b&empty="
println query.Get(text, "q"),
query.Get(text, "page"),
query.Has(text, "empty"),
query.Has(text, "x")
println query.GetAll(text, "tag")
mut m := try query.Decode(text)
println query.Size(m), query.Keys(m)
query.Add(m, "tag", "c")
query.Set(m, "page", "3")
println query.Remove(m, "empty")
println query.Encode(m)
mut keep := Vector {} as Vector<str>
keep.Push("q")
query.Retain(m, keep)
println query.Encode(m)
opts := query.QueryOptions {}
println query.EncodeWith(try query.DecodeWith("b=2&a=1", opts), opts)
empty := query.NewQueryMap()
println query.Size(empty)
println query.Get("off=50%", "off")
try:
_ := query.Decode("off=50%")
catch e:
println e.ToStr()
end
endhello 2 true false ["a", "b"] 4 ["q", "page", "tag", "empty"] true q=hello&page=3&tag=a&tag=b&tag=c q=hello b=2&a=1 0 50% query: incomplete percent escape (line 1, column 7)