#net/url
Xu 0.16.0 API
import: #net/url
counts: 10 functions, 22 methods, 2 types, 0 constants, 0 method sets
URL and query encode/decode.
struct URL
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
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
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
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
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
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
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
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
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
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
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
Purpose
new_url returns an empty URL for in-place parse.
Parameters
No arguments are required.
Returns
URL — a value of this type
parse
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
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
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
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
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
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
Purpose
Construct query.
Parameters
No arguments are required.
Returns
Query — a value of this type
(Query) len
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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