Axle v0.14.1
Package

std/text/encoding

std/encoding — text-friendly serializations of byte data, in pure
Axle. Hex is fixed-format (lowercase, no spaces). Base64 follows
RFC 4648: the standard alphabet (+/) with = padding, and a
URL-safe variant (-_, no padding).

Operates on string carrying UTF-8 bytes — the "encode this text"
/ "decode this token back to text" path. Encoders read the input's
raw bytes (byteAt) and emit pure-ASCII output. Decoders rebuild
the original bytes into a scratch buffer and validate them as UTF-8
before materialising a string; a malformed encoding or non-UTF-8
result raises ParseException, never a silently-corrupted value.

Free functions

TypeMethod and description
i32
__b64Char(symbol : i32, urlSafe : bool) : i32 Base64 alphabet character (ASCII) for a 6-bit symbol 0..63.
urlSafe selects -_ for 62/63 instead of +/.
i32
__b64Symbol(ch : i32, urlSafe : bool) : i32 6-bit symbol value 0..63 for a base64 alphabet byte, or -1 if the
byte is not in the selected alphabet.
string
hexEncode(s : string) : string Lowercase, fixed-width hex of the input's bytes ("hi" → "6869").
string
hexDecode(s : string) : string Inverse of [hexEncode]. Raises ParseException on an odd length,
a non-hex digit, or bytes that do not form valid UTF-8.
string
__b64Encode(s : string, urlSafe : bool) : string Encode the input's bytes as base64. urlSafe picks the -_
alphabet and drops = padding (the standard form uses +/ and
pads to a multiple of four characters).
string
__b64Decode(s : string, urlSafe : bool) : string Decode base64 (either alphabet via urlSafe). Whitespace and =
padding are ignored; any other out-of-alphabet byte, a dangling
single symbol, or non-UTF-8 output raises ParseException.
string
base64Encode(s : string) : string Standard RFC 4648 base64 (+/ alphabet, = padding).
string
base64Decode(s : string) : string Inverse of [base64Encode]. Whitespace and = padding are ignored;
an out-of-alphabet byte, a dangling symbol, or non-UTF-8 output
raises ParseException.
string
base64UrlEncode(s : string) : string URL-safe variant (-_ instead of +/, no padding).
string
base64UrlDecode(s : string) : string Inverse of [base64UrlEncode] (the -_ alphabet). Same validation
as [base64Decode]; padding, if present, is still tolerated.

Method detail

#__b64Char

__b64Char(symbol : i32, urlSafe : bool) : i32

Base64 alphabet character (ASCII) for a 6-bit symbol 0..63.
urlSafe selects -_ for 62/63 instead of +/.

Parameters
symbol 6-bit symbol value, 0..63
urlSafe use the -_ URL-safe alphabet instead of +/

#__b64Symbol

__b64Symbol(ch : i32, urlSafe : bool) : i32

6-bit symbol value 0..63 for a base64 alphabet byte, or -1 if the
byte is not in the selected alphabet.

Parameters
ch candidate alphabet byte (ASCII code point)
urlSafe decode against the -_ URL-safe alphabet instead of +/

#hexEncode

hexEncode(s : string) : string

Lowercase, fixed-width hex of the input's bytes ("hi" → "6869").

Parameters
s text whose raw UTF-8 bytes are hex-encoded

#hexDecode

hexDecode(s : string) : string ! ParseException

Inverse of [hexEncode]. Raises ParseException on an odd length,
a non-hex digit, or bytes that do not form valid UTF-8.

Parameters
s even-length lowercase/uppercase hex text to decode

#__b64Encode

__b64Encode(s : string, urlSafe : bool) : string

Encode the input's bytes as base64. urlSafe picks the -_
alphabet and drops = padding (the standard form uses +/ and
pads to a multiple of four characters).

Parameters
s text whose raw UTF-8 bytes are encoded
urlSafe use the -_ alphabet and omit = padding

#__b64Decode

__b64Decode(s : string, urlSafe : bool) : string ! ParseException

Decode base64 (either alphabet via urlSafe). Whitespace and =
padding are ignored; any other out-of-alphabet byte, a dangling
single symbol, or non-UTF-8 output raises ParseException.

Parameters
s base64 text to decode
urlSafe decode against the -_ URL-safe alphabet instead of +/

#base64Encode

base64Encode(s : string) : string

Standard RFC 4648 base64 (+/ alphabet, = padding).

Parameters
s text whose raw UTF-8 bytes are encoded

#base64Decode

base64Decode(s : string) : string ! ParseException

Inverse of [base64Encode]. Whitespace and = padding are ignored;
an out-of-alphabet byte, a dangling symbol, or non-UTF-8 output
raises ParseException.

Parameters
s standard-alphabet base64 text to decode

#base64UrlEncode

base64UrlEncode(s : string) : string

URL-safe variant (-_ instead of +/, no padding).

Parameters
s text whose raw UTF-8 bytes are encoded

#base64UrlDecode

base64UrlDecode(s : string) : string ! ParseException

Inverse of [base64UrlEncode] (the -_ alphabet). Same validation
as [base64Decode]; padding, if present, is still tolerated.

Parameters
s URL-safe-alphabet base64 text to decode