XU XUv0.16.0

#net/url

import: #net/url

counts: 10 functions, 22 methods, 2 types, 0 constants, 0 method sets

URL and query encode/decode.

struct URL

XuAPI
pub struct URL {
    pub scheme string
    pub host string
    pub path string
    pub raw_query string
    pub fragment string
    pub has_auth bool
}

Purpose

Structure encapsulating scheme, host, path, raw_query, fragment.

Public fields

scheme string
field (string)
host string
host
path string
filesystem path
raw_query string
field (string)
fragment string
field (string)
has_auth bool
field (bool)

(URL) scheme

XuAPI
pub fn (u URL) scheme() string

Purpose

Execute scheme on URL.

Parameters

u URL
The URL instance used by this call (value receiver).

Returns

string — result string

(URL) host

XuAPI
pub fn (u URL) host() string

Purpose

Operation on URL: host.

Parameters

u URL
The URL instance used by this call (value receiver).

Returns

string — result string

(URL) path

XuAPI
pub fn (u URL) path() string

Purpose

Execute path on URL.

Parameters

u URL
The URL instance used by this call (value receiver).

Returns

string — result string

(URL) raw_query

XuAPI
pub fn (u URL) raw_query() string

Purpose

Operation on URL: raw query.

Parameters

u URL
The URL instance used by this call (value receiver).

Returns

string — result string

(URL) fragment

XuAPI
pub fn (u URL) fragment() string

Purpose

Execute fragment on URL.

Parameters

u URL
The URL instance used by this call (value receiver).

Returns

string — result string

(URL) query

XuAPI
pub fn (u URL) query() Query

Purpose

Execute query on URL.

Parameters

u URL
The URL instance used by this call (value receiver).

Returns

Query — a value of this type

(URL) hostname

XuAPI
pub fn (u URL) hostname() string

Purpose

Execute hostname on URL.

Parameters

u URL
The URL instance used by this call (value receiver).

Returns

string — result string

(URL) port

XuAPI
pub fn (u URL) port() string

Purpose

Operation on URL: port.

Parameters

u URL
The URL instance used by this call (value receiver).

Returns

string — result string

(URL) request_uri

XuAPI
pub fn (u URL) request_uri() string

Purpose

Operation on URL: request uri.

Parameters

u URL
The URL instance used by this call (value receiver).

Returns

string — result string

(URL) join_path

XuAPI
pub fn (u URL) join_path(elem <-> string) URL

Purpose

Operation on URL: join path.

Parameters

u URL
The URL instance used by this call (value receiver).
elem <-> string
variadic string (seen inside the function as []string)

Returns

URL — a value of this type

new_url

XuAPI
pub fn new_url() URL

Purpose

new_url returns an empty URL for in-place parse.

Parameters

No arguments are required.

Returns

URL — a value of this type

parse

XuAPI
pub fn parse(s string) URL

Purpose

Parse the input.

Parameters

s string
source string (string)

Returns

URL — a value of this type

parse_url

XuAPI
pub fn parse_url(s string) URL

Purpose

Parse as url.

Parameters

s string
source string (string)

Returns

URL — a value of this type

parse_query

XuAPI
pub fn parse_query(raw string) Query

Purpose

Parse as query.

Parameters

raw string
raw (string)

Returns

Query — a value of this type

($&URL) parse

XuAPI
pub fn (u $&URL) parse(s string) int

Purpose

parse fills u from a raw URL (RFC 3986 appendix B shape scheme://[userinfo@]host/path?query#fragment). On error the URL keeps its previous components — never a partial parse result. Throws on failure; handle the error or propagate it to the caller.

Parameters

u $&URL
The URL instance used by this call (exclusive borrow).
s string
source string (string)

Returns

int — a value of this type

(URL) to_string

XuAPI
pub fn (u URL) to_string() string

Purpose

to_string re-emits the URL from its stored components ( URL.String).

Parameters

u URL
The URL instance used by this call (value receiver).

Returns

string — result string

struct Query

XuAPI
pub struct Query {
    pub keys []string
    pub vals []string
}

Purpose

Structure encapsulating keys, vals.

Public fields

keys []string
field ([]string)
vals []string
field ([]string)

new_query

XuAPI
pub fn new_query() Query

Purpose

Construct query.

Parameters

No arguments are required.

Returns

Query — a value of this type

(Query) len

XuAPI
pub fn (q Query) len() int

Purpose

Operation on Query: return the length.

Parameters

q Query
The Query instance used by this call (value receiver).

Returns

int — a value of this type

(Query) at

XuAPI
pub fn (q Query) at(i int) string

Purpose

Execute at on Query.

Parameters

q Query
The Query instance used by this call (value receiver).
i int
index or integer (int)

Returns

string — result string

($&Query) parse

XuAPI
pub fn (q $&Query) parse(query string) int

Purpose

parse decodes a query string into parallel keys/vals ('+' is a space, %XX are unescaped). Bad escapes throw — never a partial result. Throws on failure; handle the error or propagate it to the caller.

Parameters

q $&Query
The Query instance used by this call (exclusive borrow).
query string
query (string)

Returns

int — a value of this type

query_unescape

XuAPI
pub fn query_unescape(s &string) string

Purpose

query_escape percent-encodes for a query component: unreserved (a-Za-z0-9-._~) kept, space becomes '+', everything else %XX. Throws on failure; handle the error or propagate it to the caller.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

path_unescape

XuAPI
pub fn path_unescape(s &string) string

Purpose

Path unescape. Throws on failure; handle the error or propagate it to the caller.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

(Query) get

XuAPI
pub fn (q Query) get(key string) string

Purpose

Execute get on Query.

Parameters

q Query
The Query instance used by this call (value receiver).
key string
key (string)

Returns

string — result string

($&Query) set

XuAPI
pub fn (q $&Query) set(key string, val string)

Purpose

Execute set on $&Query.

Parameters

q $&Query
The Query instance used by this call (exclusive borrow).
key string
key (string)
val string
value (string)

Returns

This call does not return a value.

($&Query) add

XuAPI
pub fn (q $&Query) add(key string, val string)

Purpose

Operation on $&Query: add.

Parameters

q $&Query
The Query instance used by this call (exclusive borrow).
key string
key (string)
val string
value (string)

Returns

This call does not return a value.

($&Query) del

XuAPI
pub fn (q $&Query) del(key string)

Purpose

Delete the entry matching the given key or identifier.

Parameters

q $&Query
The Query instance used by this call (exclusive borrow).
key string
key (string)

Returns

This call does not return a value.

(Query) has

XuAPI
pub fn (q Query) has(key string) bool

Purpose

Execute has on Query.

Parameters

q Query
The Query instance used by this call (value receiver).
key string
key (string)

Returns

bool — true or false

(Query) encode

XuAPI
pub fn (q Query) encode() string

Purpose

Operation on Query: encode data into output format.

Parameters

q Query
The Query instance used by this call (value receiver).

Returns

string — result string

query_escape

XuAPI
pub fn query_escape(s &string) string

Purpose

Query escape.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

path_escape

XuAPI
pub fn path_escape(s &string) string

Purpose

path_escape percent-encodes a full path, keeping '/' and sub-delims ($&+,/:;=@) plus unreserved characters. Use path_segment_escape for a single path segment.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

path_segment_escape

XuAPI
pub fn path_segment_escape(s &string) string

Purpose

path_segment_escape percent-encodes a single path segment (escaping '/', ':', '&', etc. so segment boundaries and delimiters are preserved).

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

(&URL) resolve_reference

XuAPI
pub fn (base &URL) resolve_reference(ref string) URL

Purpose

resolve_reference implements RFC 3986 section 5.2 reference resolution. Throws on failure; handle the error or propagate it to the caller.

Parameters

base &URL
The URL instance used by this call (borrow).
ref string
ref (string)

Returns

URL — a value of this type