Axle v0.14.1
Package

std/text/url

std/url — URL percent-encoding + scheme/host/path decomposition, in
pure Axle.

urlEncode follows the RFC 3986 unreserved set: A-Za-z0-9-._~
pass through, everything else becomes %HH (uppercase hex).
urlEncodeForm additionally maps space to +
(application/x-www-form-urlencoded). Decoding validates the rebuilt
bytes as UTF-8 and raises ParseException on a truncated escape, a
non-hex digit, or a non-UTF-8 result.

Decomposition is best-effort — a missing component yields "" (or -1
for the port). It mirrors the reference splitting: the scheme is the
text before the first : when that prefix is scheme-shaped; the
authority is what follows // up to the next / ? #; the host
drops any user@ prefix and :port suffix.

The structural ASCII bytes are named in each function (module-level
const is unsupported) so the branches read in characters.

Free functions

TypeMethod and description
bool
__isUnreserved(byte : i32) : bool RFC 3986 unreserved byte: A-Za-z0-9 plus - _ . ~.
bool
__isSchemeByte(byte : i32) : bool Byte allowed in a URL scheme: A-Za-z0-9 plus + - ..
string
__substr(s : string, start : i64, end : i64) : string Materialise the bytes of [start, end) as an owned string.
string
__pctEncode(s : string, plusForSpace : bool) : string Percent-encode s. Unreserved bytes pass through; when
plusForSpace is set a space becomes +; every other byte becomes
%HH with uppercase hex.
string
__pctDecode(s : string, plusIsSpace : bool) : string Percent-decode s. %HH becomes the byte; when plusIsSpace is
set + becomes a space; other bytes pass through. Raises
ParseException on a truncated escape, a non-hex digit, or a
non-UTF-8 result.
string
urlEncode(s : string) : string Percent-encode s per RFC 3986: the unreserved set A-Za-z0-9-._~
passes through, every other byte becomes %HH with uppercase hex.
string
urlDecode(s : string) : string Inverse of [urlEncode]. Raises ParseException on a truncated
escape, a non-hex digit, or a non-UTF-8 result.
string
urlEncodeForm(s : string) : string Like [urlEncode] but in application/x-www-form-urlencoded form:
a space becomes + instead of %20.
string
urlDecodeForm(s : string) : string Inverse of [urlEncodeForm]: + decodes back to a space, %HH to
its byte. Raises ParseException on a malformed escape or non-UTF-8
result.
i64
__schemeColon(url : string, srcLen : i64) : i64 Index of the : ending a scheme-shaped prefix, or -1 when the URL
has no scheme (empty prefix, or a non-scheme byte before the first
:).
i64
__afterScheme(url : string, srcLen : i64) : i64 Byte offset just after the scheme (0 when there is none).
bool
__hasAuthority(url : string, srcLen : i64, from : i64) : bool true when an authority (//...) begins at from.
i64
__authorityEnd(url : string, srcLen : i64, authStart : i64) : i64 End of the authority region that starts at authStart: the next
/, ?, or #, or the URL end.
i64
__parseI32OrNeg(s : string, start : i64, end : i64) : i64 Parse [start, end) as a decimal i32 (optional leading sign), or -1
when empty, non-numeric, or out of the i32 range — matching the
native port parse with its -1 fallback.
string
urlScheme(url : string) : string Scheme, e.g. "https" (or "" when absent).
string
urlHost(url : string) : string Host, e.g. "example.com" — userinfo and port stripped (or "" when
there is no authority).
i32
urlPort(url : string) : i32 Port number, or -1 when absent / unparseable.
string
urlPath(url : string) : string Path, e.g. "/api/v1" (or "" when absent).
string
urlQuery(url : string) : string Query string between ? and # (or end), e.g. "k=v&x=y".
string
urlFragment(url : string) : string Fragment after #, e.g. "section" (or "" when absent).

Method detail

#__isUnreserved

__isUnreserved(byte : i32) : bool

RFC 3986 unreserved byte: A-Za-z0-9 plus - _ . ~.

Parameters
byte candidate byte (ASCII code point) to classify

#__isSchemeByte

__isSchemeByte(byte : i32) : bool

Byte allowed in a URL scheme: A-Za-z0-9 plus + - ..

Parameters
byte candidate byte (ASCII code point) to classify

#__substr

__substr(s : string, start : i64, end : i64) : string

Materialise the bytes of [start, end) as an owned string.

Parameters
s source string
start inclusive start byte offset into s, 0-based
end exclusive end byte offset into s

#__pctEncode

__pctEncode(s : string, plusForSpace : bool) : string

Percent-encode s. Unreserved bytes pass through; when
plusForSpace is set a space becomes +; every other byte becomes
%HH with uppercase hex.

Parameters
s text whose raw bytes are percent-encoded
plusForSpace encode a space as + instead of %20

#__pctDecode

__pctDecode(s : string, plusIsSpace : bool) : string ! ParseException

Percent-decode s. %HH becomes the byte; when plusIsSpace is
set + becomes a space; other bytes pass through. Raises
ParseException on a truncated escape, a non-hex digit, or a
non-UTF-8 result.

Parameters
s percent-encoded text to decode
plusIsSpace decode + back to a space

#urlEncode

urlEncode(s : string) : string

Percent-encode s per RFC 3986: the unreserved set A-Za-z0-9-._~
passes through, every other byte becomes %HH with uppercase hex.

Parameters
s text to percent-encode

#urlDecode

urlDecode(s : string) : string ! ParseException

Inverse of [urlEncode]. Raises ParseException on a truncated
escape, a non-hex digit, or a non-UTF-8 result.

Parameters
s percent-encoded text to decode

#urlEncodeForm

urlEncodeForm(s : string) : string

Like [urlEncode] but in application/x-www-form-urlencoded form:
a space becomes + instead of %20.

Parameters
s text to form-encode

#urlDecodeForm

urlDecodeForm(s : string) : string ! ParseException

Inverse of [urlEncodeForm]: + decodes back to a space, %HH to
its byte. Raises ParseException on a malformed escape or non-UTF-8
result.

Parameters
s form-encoded text to decode

#__schemeColon

__schemeColon(url : string, srcLen : i64) : i64

Index of the : ending a scheme-shaped prefix, or -1 when the URL
has no scheme (empty prefix, or a non-scheme byte before the first
:).

Parameters
url URL text to inspect
srcLen byte length of url

#__afterScheme

__afterScheme(url : string, srcLen : i64) : i64

Byte offset just after the scheme (0 when there is none).

Parameters
url URL text to inspect
srcLen byte length of url

#__hasAuthority

__hasAuthority(url : string, srcLen : i64, from : i64) : bool

true when an authority (//...) begins at from.

Parameters
url URL text to inspect
srcLen byte length of url
from byte offset at which to test for //

#__authorityEnd

__authorityEnd(url : string, srcLen : i64, authStart : i64) : i64

End of the authority region that starts at authStart: the next
/, ?, or #, or the URL end.

Parameters
url URL text to inspect
srcLen byte length of url
authStart byte offset where the authority region begins

#__parseI32OrNeg

__parseI32OrNeg(s : string, start : i64, end : i64) : i64

Parse [start, end) as a decimal i32 (optional leading sign), or -1
when empty, non-numeric, or out of the i32 range — matching the
native port parse with its -1 fallback.

Parameters
s source string
start inclusive start byte offset of the decimal digits
end exclusive end byte offset of the decimal digits

#urlScheme

urlScheme(url : string) : string

Scheme, e.g. "https" (or "" when absent).

Parameters
url URL to decompose

#urlHost

urlHost(url : string) : string

Host, e.g. "example.com" — userinfo and port stripped (or "" when
there is no authority).

Parameters
url URL to decompose

#urlPort

urlPort(url : string) : i32

Port number, or -1 when absent / unparseable.

Parameters
url URL to decompose

#urlPath

urlPath(url : string) : string

Path, e.g. "/api/v1" (or "" when absent).

Parameters
url URL to decompose

#urlQuery

urlQuery(url : string) : string

Query string between ? and # (or end), e.g. "k=v&x=y".

Parameters
url URL to decompose

#urlFragment

urlFragment(url : string) : string

Fragment after #, e.g. "section" (or "" when absent).

Parameters
url URL to decompose