Query strings v0.1.0

Source
Reading and building the name-value pairs of a query.

QueryPair

pub struct QueryPair {
    pub name: char8[..];
    pub value: char8[..];
}

One name=value pair of a query, both still percent-encoded. Copy.

Source

Fields

NameTypeDescription
namechar8[..]The name, before the first =.
valuechar8[..]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.

Source

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

Source

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

Source

Pairs

pub func Pairs(query: char8[..]) -> QueryPairs

The pairs of query, a query without its ?, such as the one Url::Query returns.

Source

Parameters

NameTypeDescription
querychar8[..]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.

Source

Parameters

NameTypeDescription
allocatorAllocatorwhat the text is kept in
encodedchar8[..]the component, such as a path segment or a query value
formboolwhether + 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.

Source

Constructors

QueryBuilder

pub func QueryBuilder(allocator: Allocator) -> QueryBuilder

An empty query.

NameTypeDescription
allocatorAllocatorwhat the query is kept in

Returns: the builder

Source

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.

NameTypeDescription
namechar8[..]the name, as text
valuechar8[..]the value, as text

Returns: nothing, or fails when the allocator refused

Source

Text

pub func Text(self: &QueryBuilder) -> char8[..]

The query built so far, without a ?, ready for Url::SetQuery.

Returns: the query

Source