Query strings v0.1.0
QueryPair
pub struct QueryPair {
pub name: char8[..];
pub value: char8[..];
}
One name=value pair of a query, both still percent-encoded. Copy.
Fields
| Name | Type | Description |
|---|---|---|
name | char8[..] | The name, before the first =. |
value | char8[..] | The value, after the first =, or empty when there is no =. |
QueryPairs
pub struct QueryPairs {
// private fields
}
A walk over a query's pairs, in order, skipping empty ones. Copy.
Methods
Iterate
pub func Iterate(self: &QueryPairs) -> QueryPairs
The walk itself, so that for pair in Pairs(query) reads every pair.
Returns: a copy of this walk
Implements Iterator
QueryPairs conforms to Iterator.
Next
pub func Next(self: &var QueryPairs) -> QueryPair?
The next pair, or none after the last.
Returns: the pair
Pairs
pub func Pairs(query: char8[..]) -> QueryPairs
The pairs of query, a query without its ?, such as the one Url::Query returns.
Parameters
| Name | Type | Description |
|---|---|---|
query | char8[..] | the query |
Returns: a walk over its pairs
Decode
pub func Decode(
allocator: Allocator,
encoded: char8[..],
form: bool
) -> String ! UrlError
Decodes a percent-encoded component into text. With form, a + is read as a space, as in a query.
Parameters
| Name | Type | Description |
|---|---|---|
allocator | Allocator | what the text is kept in |
encoded | char8[..] | the component, such as a path segment or a query value |
form | bool | whether + stands for a space |
Returns: the text, or fails when an escape is malformed or the bytes are not UTF-8
QueryBuilder
pub struct QueryBuilder {
// private fields
}
Builds a query from name=value pairs, encoding each the way HTML forms do.
Not copied.
Constructors
QueryBuilder
pub func QueryBuilder(allocator: Allocator) -> QueryBuilder
An empty query.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | what the query is kept in |
Returns: the builder
Methods
Append
pub func Append(
self: &var QueryBuilder,
name: char8[..],
value: char8[..]
) -> ! UrlError
Appends a pair, encoding the name and the value: letters, digits, *, -, . and _ stay, a space becomes
+, and every other byte is percent-encoded.
| Name | Type | Description |
|---|---|---|
name | char8[..] | the name, as text |
value | char8[..] | the value, as text |
Returns: nothing, or fails when the allocator refused
Text
pub func Text(self: &QueryBuilder) -> char8[..]
The query built so far, without a ?, ready for Url::SetQuery.
Returns: the query