stdlib.convert¶
Type Conversion Traits
Generated from
v0.60.1. 61 source files, 309 documented symbols.
ascii85.xi¶
fn to_ascii85(data: &Vec[UInt8]) -> Str¶
Encodes bytes as an Ascii85 string. Runs of four zero bytes collapse to 'z'; a final partial group is padded with zero bytes on the right and only the needed characters are emitted. Empty input yields "". Complexity: O(n).
fn from_ascii85(s: Str) -> Result[Vec[UInt8], Str]¶
Decodes an Ascii85 string back into bytes. Accepts 'z' for zero runs. Returns Err on an invalid character, a 'z' inside a group, an out-of-range group value, or a degenerate tail group. Complexity: O(n).
fn ascii85_encode_str(s: Str) -> Str¶
Encodes a string's UTF-8 bytes as Ascii85. Complexity: O(n).
fn ascii85_decode_str(s: Str) -> Result[Str, Str]¶
Decodes Ascii85 into a UTF-8 string (bytes copied verbatim; the caller is responsible for the UTF-8 validity of the decoded content). Returns Err on invalid Ascii85. Complexity: O(n).
asref.xi¶
fn as_ref_bytes[T](v: &T) -> &Vec[UInt8]¶
View a value as raw bytes (unsafe reinterpretation of the value's memory as a Vec[UInt8]). Parameters: v -- the value to view. Returns: a reference to the value's bytes. Complexity: O(1). NOTE: unsound for values that are not plain data; provided for diagnostics only.
- Precondition:
true
fn as_mut_bytes[T](v: &mut T) -> &mut Vec[UInt8]¶
View a value as mutable raw bytes (unsafe reinterpretation of the value's memory as a Vec[UInt8]). Parameters: v -- the value to view. Returns: a mutable reference to the value's bytes. Complexity: O(1). NOTE: unsound for values that are not plain data; provided for diagnostics only.
- Precondition:
true
fn as_ptr[T](v: &T) -> Int¶
Return a pointer to a value. Parameters: v -- the value. Returns: the address of the value as an Int (never 0 for a valid reference). Complexity: O(1).
- Precondition:
true
atoi.xi¶
fn atoi(s: Str) -> Int¶
Parses a decimal integer, returning zero on failure. C atoi semantics: leading whitespace is skipped, an optional sign is accepted, and parsing stops at the first non-digit. Overflow clamps to INT_MAX/INT_MIN. Complexity: O(n), n = string length.
fn atoi_radix(s: Str, radix: Int) -> Int¶
Parses an integer in the given radix (2-36), returning zero on failure or an invalid radix. C-style prefix skipping; overflow clamps. Complexity: O(n), n = string length.
fn atoi_or(s: Str, default: Int) -> Int¶
Parses a decimal integer with a fallback value: returns
defaultwhen no digits can be parsed (a genuine "0" still returns 0). Complexity: O(n), n = string length.
base16.xi¶
fn hex_encode(data: &Vec[UInt8]) -> Str¶
Encodes bytes as a lowercase hexadecimal string (two hex digits per byte). Empty input yields "". Complexity: O(n).
fn hex_decode(s: Str) -> Result[Vec[UInt8], Str]¶
Decodes a hexadecimal string back into bytes. Accepts both digit cases. Returns Err on an odd length or an invalid hex character.
fn hex_encode_str(s: Str) -> Str¶
Encodes a string's UTF-8 bytes as a lowercase hex string.
fn hex_decode_str(s: Str) -> Result[Str, Str]¶
Decodes a hex string into a UTF-8 string. The decoded bytes are copied verbatim; callers are responsible for UTF-8 validity of their hex input. Returns Err on invalid hex.
base32.xi¶
fn base32_encode(data: &Vec[UInt8]) -> Str¶
Encodes bytes as a base32 string (RFC 4648 alphabet A-Z, 2-7), padded with '=' to a multiple of 8 characters. Complexity: O(n).
fn base32_decode(s: Str) -> Result[Vec[UInt8], Str]¶
Decodes a base32 string to bytes. Returns Err on invalid input.
fn base32hex_encode(data: &Vec[UInt8]) -> Str¶
Encodes bytes as a base32hex string (RFC 4648 S7, alphabet 0-9, A-V), padded with '='. Complexity: O(n).
fn base32hex_decode(s: Str) -> Result[Vec[UInt8], Str]¶
Decodes a base32hex string to bytes. Returns Err on invalid input.
base58.xi¶
fn to_base58(value: Int) -> Str¶
Converts an integer to its base58 representation ("123456789ABCDEFGHJKLMNPQ RSTUVWXYZabcdefghijkmnopqrstuvwxyz"). 0 yields "1"; negatives get a "-" prefix. Delegates to xiom.num.convert.to_base58 for every value except INT_MIN, whose exact magnitude rendering is pinned here (num's negation overflows). Complexity: O(log_58 n).
fn from_base58(s: Str) -> Result[Int, Str]¶
Parses a base58 string into an Int. An optional leading '-'/'+' is accepted. Returns Err on an empty string, an invalid character, or overflow. Negative magnitudes accumulate in signed space, so INT_MIN round-trips exactly. Complexity: O(n), n = string length.
fn base58_encode(data: &Vec[UInt8]) -> Str¶
Encodes bytes as a base58 string (big-endian base-256 value written in base 58). Leading zero bytes produce leading '1' characters, matching the Bitcoin convention. Empty input yields "". Complexity: O(n^2) worst case (per-byte long division), O(n * log_58(2^8n)) typical.
fn base58_decode(s: Str) -> Result[Vec[UInt8], Str]¶
Decodes a base58 string back into bytes. Leading '1' characters map back to leading zero bytes. Returns Err on an invalid character. Empty input yields an empty byte vector. Complexity: O(n^2) worst case.
fn base58check_encode(data: &Vec[UInt8]) -> Str¶
Encodes bytes as base58 with a trailing 4-byte checksum, matching the base58check shape. FALLBACK: the checksum is Adler-32, not double-SHA256 (see the TODO(compiler) note) -- the output is NOT Bitcoin-interoperable. Complexity: O(n^2) worst case.
fn base58check_decode(s: Str) -> Result[Vec[UInt8], Str]¶
Decodes and verifies a base58check string. The trailing 4-byte checksum is recomputed and compared; returns Err on invalid base58, truncated data, or a checksum mismatch. FALLBACK checksum: Adler-32 (see base58check_encode). Complexity: O(n^2) worst case.
base62.xi¶
fn to_base62(value: Int) -> Str¶
Converts an integer to its base62 representation ("0-9A-Za-z"). 0 yields "0"; negatives get a "-" prefix. INT_MIN is rendered exactly via negative- digit extraction. Complexity: O(log_62 n).
fn from_base62(s: Str) -> Result[Int, Str]¶
Parses a base62 string into an Int. An optional leading '-'/'+' is accepted. Returns Err on an empty string, an invalid character, or overflow. Negative magnitudes accumulate in signed space, so INT_MIN round-trips exactly. Complexity: O(n), n = string length.
fn base62_encode(data: &Vec[UInt8]) -> Str¶
Encodes bytes as a base62 string (big-endian base-256 value written in base 62). Leading zero bytes produce leading '0' characters. Empty input yields "". Complexity: O(n^2) worst case.
fn base62_decode(s: Str) -> Result[Vec[UInt8], Str]¶
Decodes a base62 string back into bytes. Leading '0' characters map back to leading zero bytes. Returns Err on an invalid character. Empty input yields an empty byte vector. Complexity: O(n^2) worst case.
base64.xi¶
fn base64_encode(data: &Vec[UInt8]) -> Str¶
Encodes bytes as a standard base64 string with '=' padding. Empty input yields "". Complexity: O(n).
fn base64_decode(s: Str) -> Result[Vec[UInt8], Str]¶
Decodes a standard base64 string to bytes. Accepts optional '=' padding. Returns Err on a non-multiple-of-4 length or an invalid character.
fn base64_encode_str(s: Str) -> Str¶
Encodes a string's UTF-8 bytes as standard base64. Complexity: O(n).
fn base64_decode_str(s: Str) -> Result[Str, Str]¶
Decodes base64 into a UTF-8 string (bytes copied verbatim; callers are responsible for UTF-8 validity). Returns Err on invalid base64.
base64url.xi¶
fn base64url_encode(data: &Vec[UInt8]) -> Str¶
Encodes bytes as an unpadded URL-safe base64 string (alphabet A-Za-z0-9-_). Empty input yields "". Complexity: O(n).
fn base64url_decode(s: Str) -> Result[Vec[UInt8], Str]¶
Decodes an unpadded URL-safe base64 string to bytes. Optional '=' padding is tolerated. Returns Err on an invalid character. Complexity: O(n).
fn base64url_encode_str(s: Str) -> Str¶
Encodes a string's UTF-8 bytes as URL-safe base64. Complexity: O(n).
fn base64url_decode_str(s: Str) -> Result[Str, Str]¶
Decodes URL-safe base64 into a UTF-8 string (bytes copied verbatim; the caller is responsible for the UTF-8 validity of the decoded content). Returns Err on invalid base64url. Complexity: O(n).
bytes.xi¶
fn to_bytes(n: Int) -> Vec[UInt8]¶
Little-endian byte representation of
n(8 bytes).
fn from_bytes(bytes: &Vec[UInt8]) -> Int¶
TODO(compiler):
from_bytescollides with a compiler-builtin name. Any call to a module function namedfrom_bytestaking a&Vec[T](or Str) parameter produces invalid LLVM IR ("invalid getelementptr indices" on %struct.Vec) -- verified by minimal probe. The real algorithm is kept below (it is correct once the name collision is fixed); callers must avoid it until then.
fn bytes_to_hex(bytes: &Vec[UInt8]) -> Str¶
Lowercase hex encoding of the bytes.
fn hex_to_bytes(s: Str) -> Result[Vec[UInt8], Str]¶
Decode hex (either case); Err on odd length or a bad digit.
fn bytes_concat(a: &Vec[UInt8], b: &Vec[UInt8]) -> Vec[UInt8]¶
Concatenation of
afollowed byb.
fn bytes_reverse(bytes: &Vec[UInt8]) -> Vec[UInt8]¶
Copy of the bytes in reverse order.
checked.xi¶
fn checked_add(a: Int, b: Int) -> Option[Int]¶
a + b, returning None on overflow. Complexity: O(1).
fn checked_sub(a: Int, b: Int) -> Option[Int]¶
a - b, returning None on overflow. Complexity: O(1).
fn checked_mul(a: Int, b: Int) -> Option[Int]¶
a * b, returning None on overflow. Complexity: O(1).
fn checked_div(a: Int, b: Int) -> Option[Int]¶
a / b, returning None on division by zero or INT_MIN / -1. Complexity: O(1).
fn checked_neg(a: Int) -> Option[Int]¶
-a, returning None when a == INT_MIN (no positive inverse). Complexity: O(1).
fn checked_abs(a: Int) -> Option[Int]¶
|a|, returning None when a == INT_MIN (no positive representation). Complexity: O(1).
fn checked_pow(a: Int, e: Int) -> Option[Int]¶
a^e via square-and-multiply, returning None on overflow or a negative exponent. Complexity: O(log e).
fn checked_shl(a: Int, n: Int) -> Option[Int]¶
a << n, returning None when bits are shifted out of the value or the shift amount is outside [0, 64). Overflow is detected by verifying that an arithmetic shift back reproduces a. Complexity: O(1).
fn checked_shr(a: Int, n: Int) -> Option[Int]¶
a >> n (arithmetic), returning None when the shift amount is outside [0, 64). Complexity: O(1).
convert.xi¶
fn identity[T](x: T) -> T¶
Identity conversion
fn int_to_float(n: Int) -> Float64¶
Common conversions
fn float_to_int(f: Float64) -> Int¶
Truncate a Float64 toward zero.
fn int_to_string(n: Int) -> Str¶
Decimal string for an Int.
fn float_to_fixed_str(f: Float64, decimals: Int) -> Str¶
Formats
fin fixed-point notation with exactlydecimalsfraction digits (rounded half away from zero). Handles sign, "nan" and "inf". Complexity: O(decimals).
fn float_to_sci_str(f: Float64, decimals: Int) -> Str¶
Formats
fin scientific notation "d.ddde+/-XX" withdecimalsfraction digits (rounded half away from zero). Handles sign, "nan" and "inf". Complexity: O(|exp10| + decimals).
fn float_to_string(f: Float64) -> Str¶
Default Float64 -> Str conversion: 15 significant digits, fixed notation for 1e-4 <= |f| < 1e15, scientific otherwise (C
%.15gsemantics with trailing zeros stripped). Handles "nan"/"inf". Complexity: O(|exp10| + 15).
- Postcondition:
result.len() > 0
fn bool_to_string(b: Bool) -> Str¶
"true" or "false".
fn char_to_int(c: Char) -> Int¶
Unicode code point of a Char.
fn int_to_char(n: Int) -> Option[Char]¶
Char for a valid Unicode scalar value, or None.
- Postcondition:
true
cstring.xi¶
fn from_cstring(ptr: Int) -> Str¶
Copy a NUL-terminated C string into a XIOM string. Parameters: ptr -- the address of the C string (0 returns ""). Returns: the XIOM string. Complexity: O(n), n = string length.
fn to_cstring(s: Str) -> Int¶
Allocate a NUL-terminated copy of a XIOM string and return its pointer. Parameters: s -- the string to copy. Returns: a malloc'd pointer the caller must free with xiom.ffi.free. Complexity: O(n).
fn cstring_len(ptr: Int) -> Int¶
Length of a C string excluding the terminating NUL. Parameters: ptr -- the address of the C string (0 returns 0). Returns: the byte count before the first NUL. Complexity: O(n).
fn cstring_copy(ptr: Int) -> Int¶
Duplicate a C string and return the new pointer. Parameters: ptr -- the address of the source C string. Returns: a malloc'd copy the caller must free. Complexity: O(n).
date.xi¶
fn date_new(year: Int, month: Int, day: Int) -> Date¶
Build a calendar date from year, month and day. No validation is performed (out-of-range fields are carried as-is by the Date type). Parameters: year (proleptic Gregorian), month 1..12, day 1..31. Returns: the constructed Date. Complexity: O(1).
fn date_now() -> Date¶
The current calendar date, computed from the Unix clock. Returns: today's Date (UTC). Complexity: O(1).
fn date_iso8601(d: &Date) -> Str¶
Format a date as ISO 8601 "YYYY-MM-DD", zero-padded. Parameters: d -- the date to format. Returns: the formatted string (always 10 bytes). Complexity: O(1).
fn date_from_iso8601(s: Str) -> Option[Date]¶
Parse an ISO 8601 "YYYY-MM-DD" string into a Date. Parameters: s -- the date string. Returns: Some(Date) when well-formed and within calendar range, None otherwise (malformed layout or out-of-range fields). Complexity: O(1).
fn date_weekday(d: &Date) -> Int¶
Day of the week for a date: 0 = Sunday .. 6 = Saturday. Parameters: d -- the date. Returns: weekday index. Complexity: O(1).
fn date_day_of_year(d: &Date) -> Int¶
Ordinal day of the year for a date (1..366, leap-aware). Parameters: d -- the date. Returns: the day-of-year index. Complexity: O(month) in the worst case (small constant).
datetime.xi¶
fn datetime_new(year: Int, month: Int, day: Int, hour: Int, minute: Int, second: Int) -> DateTime¶
Build a date-time value from its calendar and clock fields. Parameters: year, month, day, hour, minute, second (24-hour clock). Returns: a DateTime whose weekday is computed from the calendar date. No range validation is performed. Complexity: O(1).
fn datetime_now() -> DateTime¶
The current date-time value (UTC clock). Returns: a DateTime for the current instant. Complexity: O(1).
fn datetime_iso8601(dt: &DateTime) -> Str¶
Format a date-time as ISO 8601 "YYYY-MM-DDTHH:MM:SS", zero-padded. Parameters: dt -- the date-time value. Returns: the formatted string (always 19 bytes). Complexity: O(1).
fn datetime_from_iso8601(s: Str) -> Option[DateTime]¶
Parse an ISO 8601 "YYYY-MM-DDTHH:MM:SS" string into a DateTime. Parameters: s -- the date-time string. Returns: Some(DateTime) when well-formed and within range, None otherwise. Complexity: O(1).
duration.xi¶
fn duration_seconds(n: Int) -> Duration¶
Build a Duration from whole seconds. Parameters: n -- the number of seconds (may be negative). Returns: a normalized Duration (nanos in [0, 1e9)). Complexity: O(1).
fn duration_millis(n: Int) -> Duration¶
Build a Duration from whole milliseconds. Parameters: n -- the number of milliseconds (may be negative). Returns: a normalized Duration. Complexity: O(1).
fn duration_micros(n: Int) -> Duration¶
Build a Duration from whole microseconds. Parameters: n -- the number of microseconds (may be negative). Returns: a normalized Duration. Complexity: O(1).
fn duration_nanos(n: Int) -> Duration¶
Build a Duration from whole nanoseconds. Parameters: n -- the number of nanoseconds (may be negative). Returns: a normalized Duration. Complexity: O(1).
fn duration_as_secs(d: Duration) -> Int¶
Whole seconds contained in a Duration. Parameters: d -- the duration. Returns: the seconds field (sub-second parts dropped). Complexity: O(1).
fn duration_as_ms(d: Duration) -> Int¶
Whole milliseconds contained in a Duration. Parameters: d -- the duration. Returns: the total milliseconds (sub-millisecond parts dropped). Complexity: O(1).
endian.xi¶
fn to_be_bytes(n: Int) -> Vec[UInt8]¶
Big-endian byte representation of an integer (exactly 8 bytes, MSB first). Negative values render as their two's-complement pattern. Complexity: O(1).
fn to_le_bytes(n: Int) -> Vec[UInt8]¶
Little-endian byte representation of an integer (exactly 8 bytes, LSB first). Complexity: O(1).
fn from_be_bytes(bytes: &Vec[UInt8]) -> Int¶
Integer read from big-endian bytes. Reads at most 8 bytes; returns 0 for an empty vector or more than 8 bytes. Complexity: O(n).
fn from_le_bytes(bytes: &Vec[UInt8]) -> Int¶
Integer read from little-endian bytes. Reads at most 8 bytes; returns 0 for an empty vector or more than 8 bytes. Complexity: O(n).
fn swap_bytes(n: Int) -> Int¶
Reverses the byte order of an integer (all 8 bytes). Delegates to the canonical xiom.bits.byte_swap64. Complexity: O(1).
fn is_little_endian() -> Bool¶
Reports the host byte order. The supported x86-64 targets are little-endian, so this returns true. Complexity: O(1).
escape.xi¶
fn html_escape(s: Str) -> Str¶
Escape text for HTML body content: & < > " ' become entities. Parameters: s -- the input text. Returns: the escaped text (strictly longer unless no specials). Complexity: O(n), n = input length.
fn html_unescape(s: Str) -> Str¶
Decode HTML entities back to characters: the named set (& < > " ' ') and numeric forms (&#NN; decimal, &#xHH; hex). Parameters: s -- the escaped text. Returns: the decoded text; unrecognized sequences pass through. Complexity: O(n), n = input length.
fn html_escape_attr(s: Str) -> Str¶
Escape text for use inside HTML attribute quotes: same entity set as html_escape plus both quote characters are always escaped. Parameters: s -- the attribute value text. Returns: the escaped text. Complexity: O(n).
fn xml_escape(s: Str) -> Str¶
Escape the five predefined XML entities: & " ' < >. Parameters: s -- the input text. Returns: the escaped text. Complexity: O(n).
fn xml_unescape(s: Str) -> Str¶
Decode the predefined XML entities back to characters. Parameters: s -- the escaped text. Returns: the decoded text; unrecognized sequences pass through. Complexity: O(n).
fn csv_escape_field(s: Str) -> Str¶
Escape and quote a field for RFC 4180 CSV output: the field is quoted when it contains a comma, quote, CR or LF, and embedded quotes are doubled. Parameters: s -- the raw field value. Returns: the CSV-ready field. Complexity: O(n).
fn csv_unescape_field(s: Str) -> Str¶
Parse and unquote a single CSV field: a quoted field is unquoted and doubled quotes are restored; unquoted fields pass through unchanged. Parameters: s -- a single CSV field (no separators). Returns: the raw field value. Complexity: O(n).
fn tsv_escape_field(s: Str) -> Str¶
Escape tab, CR and LF characters in a TSV field as \t, \r, \n. Parameters: s -- the raw field value. Returns: the escaped field. Complexity: O(n).
fn tsv_unescape_field(s: Str) -> Str¶
Restore tab, CR and LF escapes in a TSV field. Parameters: s -- the escaped field. Returns: the raw field value. Complexity: O(n).
fn regex_escape(s: Str) -> Str¶
Escape regex metacharacters in a literal string with a backslash. Escapes: \ . ^ $ * + ? ( ) [ ] { } |. Parameters: s -- the literal text. Returns: the regex-safe text. Complexity: O(n).
fn glob_escape(s: Str) -> Str¶
Escape glob wildcard metacharacters (* ? [ ] and backslash) in a literal string with a backslash. Parameters: s -- the literal text. Returns: the glob-safe text. Complexity: O(n).
fn glob_unescape(s: Str) -> Str¶
Restore escaped glob metacharacters: a backslash before a glob character is removed. Parameters: s -- the escaped text. Returns: the literal text. Complexity: O(n).
fn shell_escape(s: Str) -> Str¶
Escape a string for safe use in a POSIX shell command: every character outside the safe set (alphanumerics plus _ - . / , : @ % + =) is preceded by a backslash. Parameters: s -- the raw argument. Returns: the shell-escaped argument. Complexity: O(n).
fn shell_quote(s: Str) -> Str¶
Quote a string with single quotes for a POSIX shell; embedded single quotes are closed, escaped and reopened ('\''). Parameters: s -- the raw argument. Returns: the single-quoted argument. Complexity: O(n).
fn cmd_escape(s: Str) -> Str¶
Escape a string for safe use in a Windows cmd command line: ^ & | < > ( ) " % are escaped with a caret. Parameters: s -- the raw argument. Returns: the cmd-escaped argument. Complexity: O(n).
fn cmd_quote(s: Str) -> Str¶
Quote a string for a Windows cmd command line: wrap in double quotes and double any embedded quote characters. Parameters: s -- the raw argument. Returns: the double-quoted argument. Complexity: O(n).
exact.xi¶
fn exact_div(a: Int, b: Int) -> Result[Int, Str]¶
a / b, returning Err on division by zero, the INT_MIN / -1 overflow, or a non-exact quotient. Complexity: O(1).
fn exact_float(a: Float64, b: Float64) -> Option[Float64]¶
a / b in IEEE arithmetic, returning None on division by zero or when the quotient does not round-trip (q * b != a), i.e. when the division lost precision. Complexity: O(1).
fn exact_ratio(a: Int, b: Int) -> Option[(Int, Int)]¶
Reduces a/b to lowest terms as (numerator, denominator) with a positive denominator. Returns None on division by zero. Complexity: O(log max|a,b|).
float.xi¶
fn float_to_string(f: Float64) -> Str¶
Format a float with 15 significant digits: fixed notation for 1e-4 <= |f| < 1e15, scientific otherwise (C
%.15gsemantics with trailing zeros stripped). Handles "nan"/"inf". Parameters: f -- the float value. Returns: the formatted string. Complexity: O(|exp10| + 15).
fn string_to_float(s: Str) -> Result[Float64, Str]¶
Parse a string to a float. Parameters: s -- the decimal float string (optional sign, '.', 'e'/'E'). Returns: Ok(Float64) for well-formed input, Err otherwise. Complexity: O(n), n = string length.
fn float_to_fixed_str(f: Float64, decimals: Int) -> Str¶
Format a float in fixed-point notation with exactly
decimalsfraction digits (rounded half away from zero). Handles "nan"/"inf". Parameters: f -- the float value; decimals -- the fraction digit count. Returns: the formatted string. Complexity: O(decimals).
fn float_to_sci_str(f: Float64, decimals: Int) -> Str¶
Format a float in scientific notation "d.ddde+/-XX" with
decimalsfraction digits (rounded half away from zero). Handles "nan"/"inf". Parameters: f -- the float value; decimals -- the fraction digit count. Returns: the formatted string. Complexity: O(|exp10| + decimals).
fn float_to_int(f: Float64) -> Int¶
Truncate a float to an integer (toward zero). Parameters: f -- the float value. Returns: the truncated integer. Behavior for NaN/out-of-range input is undefined (use checked variants elsewhere). Complexity: O(1).
fn int_to_float(n: Int) -> Float64¶
Widen an integer to a float (exact up to 2^53). Parameters: n -- the integer value. Returns: n widened to Float64. Complexity: O(1).
from.xi¶
fn from_int(n: Int) -> Float64¶
Widen an integer to a float (exact up to 2^53). Parameters: n -- the integer value. Returns: n widened to Float64. Complexity: O(1).
fn from_float(f: Float64) -> Int¶
Truncate a float toward zero to an integer. Parameters: f -- the float value. Returns: the truncated integer. Behavior for NaN/out-of-range input is undefined (use the checked variants elsewhere). Complexity: O(1).
fn from_char(c: Char) -> Int¶
Return a character's code point as an integer. Parameters: c -- the character. Returns: the Unicode code point of c. Complexity: O(1).
fn from_bool(b: Bool) -> Int¶
Render a boolean as 0 or 1. Parameters: b -- the boolean. Returns: 1 when true, 0 when false. Complexity: O(1).
fromstr.xi¶
fn from_str_int(s: Str) -> Result[Int, Str]¶
Parse a string as an integer. Parameters: s -- the decimal integer string (optional sign). Returns: Ok(Int) for well-formed input, Err otherwise. Complexity: O(n), n = string length.
fn from_str_float(s: Str) -> Result[Float64, Str]¶
Parse a string as a float. Parameters: s -- the decimal float string (optional sign, '.', 'e'/'E'). Returns: Ok(Float64) for well-formed input, Err otherwise. Complexity: O(n), n = string length.
fn from_str_bool(s: Str) -> Option[Bool]¶
Parse a string as a boolean. Parameters: s -- the string. Returns: Some(true) for "true", Some(false) for "false" (exact, case sensitive), None otherwise. Complexity: O(1).
ftos.xi¶
fn ftos(f: Float64) -> Str¶
Float-to-string shorthand: 15 significant digits in the canonical fixed / scientific layout. Handles "nan" and "inf". Complexity: O(|exp10| + 15).
fn ftos_prec(f: Float64, prec: Int) -> Str¶
Float-to-string with exactly
precfraction digits (fixed notation, rounded half away from zero). Complexity: O(prec).
fn ftos_sci(f: Float64, prec: Int) -> Str¶
Float-to-string in scientific notation "d.ddde+/-XX" with
precfraction digits. Complexity: O(|exp10| + prec).
int.xi¶
fn int_to_string(n: Int) -> Str¶
Format an integer as a decimal string. Exact for the full Int range (including INT_MIN). Parameters: n -- the integer value. Returns: the decimal representation. Complexity: O(log_10 |n|).
fn string_to_int(s: Str) -> Result[Int, Str]¶
Parse a decimal string to an integer. Parameters: s -- the decimal integer string (optional sign). Returns: Ok(Int) for well-formed input, Err otherwise. Complexity: O(n), n = string length.
fn int_to_base(n: Int, base: Int) -> Str¶
Format an integer in an arbitrary base (2-36, lowercase digits). Parameters: n -- the integer value; base -- the radix. Returns: the base representation; "" for an invalid radix. Complexity: O(log_base |n|).
fn base_to_int(s: Str, base: Int) -> Result[Int, Str]¶
Parse an integer string in an arbitrary base (2-36, both digit cases). Parameters: s -- the digit string (optional sign); base -- the radix. Returns: Ok(Int) for well-formed input, Err for an invalid radix, an empty string, an out-of-range digit, or overflow. Complexity: O(n), n = string length.
fn int_to_hex(n: Int) -> Str¶
Format an integer as a lowercase hexadecimal string. Parameters: n -- the integer value. Returns: the hexadecimal representation ("0" for zero). Complexity: O(log_16 |n|).
fn int_from_hex(s: Str) -> Result[Int, Str]¶
Parse a hexadecimal string to an integer. Parameters: s -- the hex digit string (both digit cases accepted). Returns: Ok(Int) for well-formed input, Err otherwise. Complexity: O(n), n = string length.
fn int_to_octal(n: Int) -> Str¶
Format an integer as a lowercase octal string. Parameters: n -- the integer value. Returns: the octal representation ("0" for zero). Complexity: O(log_8 |n|).
fn int_to_binary(n: Int) -> Str¶
Format an integer as a binary string. Parameters: n -- the integer value. Returns: the binary representation ("0" for zero). Complexity: O(log_2 |n|).
into.xi¶
fn into_int(n: Float64) -> Int¶
Truncate a float toward zero to an integer. Parameters: n -- the float value. Returns: the truncated integer. Behavior for NaN/out-of-range input is undefined (use the checked variants elsewhere). Complexity: O(1).
fn into_float(n: Int) -> Float64¶
Widen an integer to a float (exact up to 2^53). Parameters: n -- the integer value. Returns: n widened to Float64. Complexity: O(1).
fn into_str[T](v: T) -> Str¶
Convert a generic value to a string via its Display to_str implementation. Parameters: v -- the value to render. Returns: the value's to_str() representation. Complexity: O(1) for primitives.
ip.xi¶
fn is_valid_ipv4(s: Str) -> Bool¶
Check that a string is a valid IPv4 address. Parameters: s -- the candidate address. Returns: true for a dotted-quad with four octets in 0..255. Complexity: O(n).
fn is_valid_ipv6(s: Str) -> Bool¶
Check that a string is a valid IPv6 address (with optional "::" compression; IPv4-mapped forms are not accepted). Parameters: s -- the candidate address. Returns: true for a well-formed IPv6 address. Complexity: O(n).
fn ipv4_to_string(octets: &Vec[UInt8]) -> Str¶
Format four octets as a dotted IPv4 address. Parameters: octets -- at least four octets (only the first four are used). Returns: the "a.b.c.d" representation. Complexity: O(1).
fn string_to_ipv4(s: Str) -> Option[Vec[UInt8]]¶
Parse a dotted IPv4 address into four octets. Parameters: s -- the address string. Returns: Some(four octets) for a valid address, None otherwise. Complexity: O(n).
fn ip_parse(s: Str) -> Option[Str]¶
Parse an IP address, returning its canonical text form (IPv4 dotted-quad or IPv6 with "::" compression). Parameters: s -- the address string. Returns: Some(canonical) for a valid address, None otherwise. Complexity: O(n).
fn ip_to_bytes(s: Str) -> Option[Vec[UInt8]]¶
Parse an IP address into its raw bytes (4 for IPv4, 16 for IPv6). Parameters: s -- the address string. Returns: Some(bytes) for a valid address, None otherwise. Complexity: O(n).
iri.xi¶
type Iri¶
Iri -- parsed IRI components.
| Field | Type |
|---|---|
scheme |
Str |
authority |
Str |
path |
Str |
query |
Str |
fragment |
Str |
fn iri_parse(s: Str) -> Result[Iri, Str]¶
Parse an IRI into its scheme, authority, path, query and fragment. Parameters: s -- the IRI string (non-ASCII characters allowed). Returns: Ok(Iri) on success; Err for an empty IRI. Complexity: O(n).
fn iri_to_uri(s: Str) -> Result[Str, Str]¶
Convert an IRI to an ASCII-only URI by percent-encoding every byte >= 0x80 in the authority, path, query and fragment. Parameters: s -- the IRI string. Returns: Ok(URI) on success; Err for an empty IRI. Complexity: O(n).
fn iri_normalize(s: Str) -> Result[Str, Str]¶
Normalize an IRI into canonical form (lowercase scheme, non-ASCII bytes percent-encoded in place). Parameters: s -- the IRI string. Returns: Ok(canonical) on success; Err for an empty IRI. Complexity: O(n).
itos.xi¶
fn itos(n: Int) -> Str¶
Integer-to-string shorthand (decimal). Complexity: O(log_10 |n|).
fn itos_padded(n: Int, width: Int) -> Str¶
Integer-to-string with zero padding to
widthcharacters (printf %0Nd style: the sign, if any, precedes the padding). Widths smaller than the digit count are ignored. Complexity: O(width).
fn itos_signed(n: Int) -> Str¶
Integer-to-string with an explicit sign: positive values get a '+' prefix; zero and negative values render normally. Complexity: O(log_10 n).
json.xi¶
fn json_escape(s: Str) -> Str¶
Escape a string for embedding in JSON (without surrounding quotes). Handles ", \, \n, \r, \t, \b, \f. Parameters: s -- the raw text. Returns: the escaped text. Complexity: O(n), n = string length.
fn json_unescape(s: Str) -> Result[Str, Str]¶
Unescape a JSON string literal (without surrounding quotes). Handles \, \", \/, \b, \f, \n, \r, \t, and \uNNNN. Parameters: s -- the escaped text. Returns: Ok(text) on success; Err on an invalid escape or a truncated \u sequence. Complexity: O(n), n = string length.
fn json_quote(s: Str) -> Str¶
Wrap a string in JSON quotes with escaping. Parameters: s -- the raw text. Returns: the quoted, escaped JSON string literal. Complexity: O(n).
fn json_is_valid(s: Str) -> Bool¶
Check that a string is valid JSON (a single top-level value). Parameters: s -- the candidate JSON text. Returns: true when the whole input parses as one JSON value. Complexity: O(n).
fn json_pretty(s: Str) -> Result[Str, Str]¶
Pretty-print a JSON string with 2-space indentation. Parameters: s -- the minified JSON text. Returns: Ok(pretty) on success; Err for invalid JSON (unterminated string or unbalanced brackets). Complexity: O(n), n = input length.
lossy.xi¶
fn lossy_from_str(s: Str) -> Int¶
Parses a decimal integer string. Returns 0 on malformed input (empty, invalid characters) and clamps to INT_MAX/INT_MIN on overflow -- the function never fails. Complexity: O(n), n = string length.
fn lossy_from_float(f: Float64) -> Int¶
Truncates a float toward zero, clamping to INT_MAX/INT_MIN on overflow. NaN yields 0. Complexity: O(1).
fn lossy_to_float(s: Str) -> Float64¶
Parses a floating-point string, returning 0.0 on any parse failure. Supports optional sign, decimal point, and 'e'/'E' exponent. Complexity: O(n), n = string length.
fn lossy_char(s: Str) -> Char¶
Returns the first character of s, or '\0' (the null character) when the string is empty. Complexity: O(1).
mac.xi¶
fn mac_parse(s: Str) -> Option[Vec[UInt8]]¶
Parse a MAC address into six octets. Parameters: s -- a MAC address using ':' or '-' separators (e.g. "aa:bb:cc:dd:ee:ff" or "AA-BB-CC-DD-EE-FF"). Returns: Some(six octets) for a well-formed address, None otherwise. Complexity: O(1).
fn mac_to_string(bytes: &Vec[UInt8]) -> Str¶
Format six octets as a colon-separated lowercase MAC address. Parameters: bytes -- at least six octets (only the first six are used). Returns: the "xx:xx:xx:xx:xx:xx" representation. Complexity: O(1).
fn mac_is_valid(s: Str) -> Bool¶
Check that a string is a valid MAC address (six hex octets, ':' or '-' separators). Parameters: s -- the candidate string. Returns: true when well-formed. Complexity: O(1).
fn mac_random() -> Str¶
Generate a random MAC address string (locally administered, unicast). Returns: a 17-character MAC address. Complexity: O(1).
network.xi¶
fn host_to_network16(n: Int) -> Int¶
Convert a 16-bit host-order value to network order (big-endian). Parameters: n -- a 16-bit value (0..65535). Returns: the byte-swapped value. Complexity: O(1).
fn host_to_network32(n: Int) -> Int¶
Convert a 32-bit host-order value to network order (big-endian). Parameters: n -- a 32-bit value. Returns: the byte-swapped value. Complexity: O(1).
fn network_to_host16(n: Int) -> Int¶
Convert a 16-bit network-order value to host order (little-endian). Parameters: n -- a 16-bit network-order value. Returns: the byte-swapped value. Complexity: O(1).
fn network_to_host32(n: Int) -> Int¶
Convert a 32-bit network-order value to host order (little-endian). Parameters: n -- a 32-bit network-order value. Returns: the byte-swapped value. Complexity: O(1).
fn htonll(n: Int) -> Int¶
Convert a 64-bit host-order value to network order (big-endian). Parameters: n -- a 64-bit value. Returns: the byte-swapped value. Complexity: O(1).
fn ntohll(n: Int) -> Int¶
Convert a 64-bit network-order value to host order (little-endian). Parameters: n -- a 64-bit network-order value. Returns: the byte-swapped value. Complexity: O(1).
overflow.xi¶
fn overflowing_add(a: Int, b: Int) -> (Int, Bool)¶
a + b, returning (wrapped_value, overflowed). Complexity: O(1).
fn overflowing_sub(a: Int, b: Int) -> (Int, Bool)¶
a - b, returning (wrapped_value, overflowed). Complexity: O(1).
fn overflowing_mul(a: Int, b: Int) -> (Int, Bool)¶
a * b, returning (wrapped_value, overflowed). Complexity: O(1).
fn overflowing_neg(a: Int) -> (Int, Bool)¶
-a, returning (wrapped_value, overflowed). INT_MIN negates to itself. Complexity: O(1).
parse.xi¶
fn parse_int(s: Str) -> Result[Int, Str]¶
Parses a decimal integer string. An optional leading '-'/'+' is accepted. Returns Err on an empty string, an invalid character, or overflow. Complexity: O(n), n = string length.
fn parse_int_radix(s: Str, radix: Int) -> Result[Int, Str]¶
Parses an integer string in the given radix (2-36, both digit cases accepted). An optional leading '-'/'+' is accepted. Returns Err on an invalid radix, an empty string, an invalid digit, a digit out of range for the radix, or overflow. Complexity: O(n), n = string length.
fn parse_float(s: Str) -> Result[Float64, Str]¶
Parses a floating-point string. Supports an optional sign, a decimal point, and an 'e'/'E' exponent. Returns Err on empty input, missing digits, invalid characters, multiple decimal points, or a malformed exponent. Complexity: O(n), n = string length.
fn parse_bool(s: Str) -> Option[Bool]¶
Parses "true" or "false" (exact, case-sensitive). Returns None otherwise. Complexity: O(1).
fn parse_char(s: Str) -> Option[Char]¶
Returns the first character of a single-character string. Returns None for an empty string or a multi-character string (documented: this helper parses exactly one character). Complexity: O(1).
percent.xi¶
fn percent_encode(s: Str) -> Str¶
Percent-encodes a full URL string. Reserved separators ('/', ':', '?', '&', '=', '+', '#', '@', etc.) pass through; all other non-unreserved characters are percent-encoded per UTF-8 byte. Complexity: O(n).
fn percent_decode(s: Str) -> Result[Str, Str]¶
Percent-decodes a URL string: '%XX' escapes are decoded; '+' is left as a literal '+'. Returns Err on a truncated or malformed escape. Complexity: O(n).
fn percent_encode_component(s: Str) -> Str¶
Percent-encodes a single URL component (path segment / query value): only unreserved characters (A-Z a-z 0-9 - _ . ~) pass through; everything else -- including '/', '?', '&', '=', ':' -- is percent-encoded per UTF-8 byte. Complexity: O(n).
fn percent_decode_component(s: Str) -> Result[Str, Str]¶
Percent-decodes a URL component: '%XX' escapes are decoded and '+' is converted to a space (application/x-www-form-urlencoded semantics). Returns Err on a truncated or malformed escape. Complexity: O(n).
punycode.xi¶
fn punycode_encode(s: Str) -> Result[Str, Str]¶
Encode a Unicode label to Punycode (with the "xn--" prefix). Parameters: s -- the Unicode label (no dots). Returns: Ok("xn--...") for a label with non-ASCII code points; Ok(s) unchanged when the label is entirely ASCII. Complexity: O(n^2) worst case, O(n) typical.
fn punycode_decode(s: Str) -> Result[Str, Str]¶
Decode a Punycode label to Unicode. Parameters: s -- the label; "xn--" prefixed labels are decoded, plain ASCII labels pass through unchanged. Returns: Ok(Unicode label) on success; Err on malformed input. Complexity: O(n^2) worst case.
fn punycode_encode_domain(domain: Str) -> Result[Str, Str]¶
Encode each label of a full domain to Punycode. Parameters: domain -- a dotted domain (labels separated by '.'). Returns: Ok(encoded domain) on success; Err for an empty label. Complexity: O(n) labels x encode cost.
fn punycode_decode_domain(domain: Str) -> Result[Str, Str]¶
Decode each label of an A-label domain to Unicode. Parameters: domain -- a dotted domain. Returns: Ok(Unicode domain) on success; Err for a malformed label. Complexity: O(n) labels x decode cost.
fn idna_to_ascii(s: Str) -> Result[Str, Str]¶
Convert an internationalized domain to its ASCII A-label form. Parameters: s -- the Unicode domain. Returns: Ok(A-label domain) on success; Err for invalid input. Complexity: O(n).
fn idna_to_unicode(s: Str) -> Result[Str, Str]¶
Convert an ASCII A-label domain to its Unicode U-label form. Parameters: s -- the A-label domain. Returns: Ok(U-label domain) on success; Err for invalid input. Complexity: O(n).
fn idna_is_valid(s: Str) -> Bool¶
Report whether a domain conforms to IDNA requirements. Parameters: s -- the candidate domain (A-label or U-label). Returns: true when every label is a valid IDNA label. Complexity: O(n).
fn idna_uts46_normalize(s: Str) -> Result[Str, Str]¶
Apply UTS-46 mapping and normalization to a domain string: case folding (lowercasing) plus IDNA character validation. Parameters: s -- the raw domain. Returns: Ok(normalized) on success; Err when an invalid character remains. Complexity: O(n).
quotedprintable.xi¶
fn qp_encode(data: &Vec[UInt8]) -> Str¶
Encode bytes to Quoted-Printable with default 76-column lines. Parameters: data -- the raw bytes. Returns: the QP-encoded text (ASCII). Complexity: O(n).
fn qp_encode_maxline(data: &Vec[UInt8], max_line: Int) -> Str¶
Encode bytes to Quoted-Printable using a custom maximum line width. Parameters: data -- the raw bytes; max_line -- the target column limit. Returns: the QP-encoded text. Complexity: O(n).
fn qp_decode(s: Str) -> Result[Vec[UInt8], Str]¶
Decode a Quoted-Printable string to bytes. Parameters: s -- the QP-encoded text. Returns: Ok(bytes) on success; Err for a truncated or invalid =HH escape. Complexity: O(n).
fn qp_soft_linebreak(s: Str, width: Int) -> Str¶
Insert soft line breaks (=CRLF) into already-encoded text. Parameters: s -- the encoded text; width -- the maximum line width. Returns: the re-wrapped text. Complexity: O(n).
fn qp_is_binary(s: Str) -> Bool¶
Report whether the string is too binary for safe Quoted-Printable use (contains NUL or more than a third of its bytes are control bytes). Parameters: s -- the candidate text. Returns: true when the content is too binary. Complexity: O(n).
fn qp_escape_byte(b: UInt8) -> Str¶
Return the =HH escape for a single byte. Parameters: b -- the byte. Returns: a three-character "=HH" string (uppercase hex). Complexity: O(1).
roundtrip.xi¶
fn roundtrip_int(s: Str) -> Bool¶
True iff s is a canonical decimal integer: parsing it succeeds and formatting the result reproduces s exactly. Complexity: O(n).
fn roundtrip_float(s: Str) -> Bool¶
True iff parsing s, formatting canonically, and re-parsing yields the same value (the value is stable under the canonical float formatter). Complexity: O(n).
fn roundtrip_fixed(f: Float64, decimals: Int) -> Bool¶
True iff formatting f with exactly
decimalsfraction digits and parsing the result back reproduces f. Complexity: O(decimals).
fn roundtrip_base(n: Int, base: Int) -> Bool¶
True iff formatting n in the given base and parsing it back reproduces n. Returns false for an invalid base (2-36 required). Complexity: O(log n).
saturating.xi¶
fn saturating_add(a: Int, b: Int) -> Int¶
a + b, clamping at INT_MAX/INT_MIN on overflow. Complexity: O(1).
fn saturating_sub(a: Int, b: Int) -> Int¶
a - b, clamping at INT_MAX/INT_MIN on overflow. Complexity: O(1).
fn saturating_mul(a: Int, b: Int) -> Int¶
a * b, clamping at INT_MAX/INT_MIN on overflow. Complexity: O(1).
fn saturating_abs(a: Int) -> Int¶
|a|, clamping to INT_MAX when a == INT_MIN (no positive representation). Complexity: O(1).
fn saturating_pow(a: Int, e: Int) -> Int¶
a^e via square-and-multiply, clamping at INT_MAX/INT_MIN on overflow. Negative exponents yield 1 (documented). Complexity: O(log e).
strftime.xi¶
fn strftime(spec: Str, d: &Date) -> Str¶
Format a date using a strftime specifier. Parameters: spec -- the format string; d -- the date. Returns: the formatted string. Unknown conversions pass through literally. Complexity: O(|spec|).
fn strftime_now(spec: Str) -> Str¶
Format the current date using a strftime specifier. Parameters: spec -- the format string. Returns: the formatted string for today's date. Complexity: O(|spec|).
strptime.xi¶
fn strptime(s: Str, spec: Str) -> DateParse¶
Parse a string with a strptime specifier. Parameters: s -- the input string; spec -- the format string. Returns: a DateParse whose is_ok is true when the input matches the spec and the parsed month/day are in range; unsupported conversions and mismatches yield is_ok = false. Complexity: O(|s| + |spec|).
fn strptime_iso8601(s: Str) -> DateParse¶
Parse an ISO 8601 "YYYY-MM-DD" date string. Parameters: s -- the date string. Returns: a DateParse with is_ok true when the string is well-formed. Complexity: O(|s|).
swap.xi¶
fn swap16(n: Int) -> Int¶
Swaps the two bytes of a 16-bit value stored in the low 16 bits of an Int. Complexity: O(1).
fn swap32(n: Int) -> Int¶
Swaps the four bytes of a 32-bit value stored in the low 32 bits of an Int. Complexity: O(1).
fn swap64(n: Int) -> Int¶
Swaps the eight bytes of a 64-bit value. Complexity: O(1).
time.xi¶
fn time_now() -> Int¶
Seconds since midnight (local time, which this runtime equates to UTC). Returns: 0..86399. Complexity: O(1).
fn timestamp_now() -> Int¶
Seconds since the Unix epoch (1970-01-01T00:00:00Z). Returns: the current epoch seconds. Complexity: O(1).
fn timestamp_to_date(ts: Int) -> Date¶
Convert a Unix timestamp (seconds since the epoch) to a calendar date. Parameters: ts -- the timestamp. Returns: the corresponding Date (UTC). Complexity: O(1).
fn date_to_timestamp(d: &Date) -> Int¶
Convert a calendar date to the Unix timestamp of its midnight (UTC). Parameters: d -- the date. Returns: epoch seconds for 00:00:00Z of that date. Complexity: O(1).
timestamp.xi¶
fn timestamp_now() -> Int¶
Seconds since the Unix epoch (1970-01-01T00:00:00Z). Returns: the current epoch seconds. Complexity: O(1).
fn timestamp_to_date(ts: Int) -> Date¶
Convert a Unix timestamp (seconds since the epoch) to a calendar date. Parameters: ts -- the timestamp. Returns: the corresponding Date (UTC). Complexity: O(1).
fn timestamp_to_datetime(ts: Int) -> DateTime¶
Convert a Unix timestamp (seconds since the epoch) to a date-time value. Parameters: ts -- the timestamp. Returns: the corresponding DateTime (UTC) with weekday computed. Complexity: O(1).
fn timestamp_from_date(d: &Date) -> Int¶
Convert a calendar date to the Unix timestamp of its midnight (UTC). Parameters: d -- the date. Returns: epoch seconds for 00:00:00Z of that date. Complexity: O(1).
fn timestamp_from_datetime(dt: &DateTime) -> Int¶
Convert a date-time value to a Unix timestamp (UTC). Parameters: dt -- the date-time value. Returns: epoch seconds for that instant. Complexity: O(1).
tofloat.xi¶
fn to_float(n: Int) -> Float64¶
Widens an integer to a float (exact up to 2^53). Complexity: O(1).
fn to_float_saturating(s: Str) -> Float64¶
Parses a string into a float, clamping on failure: malformed input (empty, no digits, invalid characters) yields 0.0. Supports sign, decimal point, and 'e'/'E' exponent. Complexity: O(n), n = string length.
fn to_float_checked(s: Str) -> Option[Float64]¶
Parses a string into a float only when the input is well-formed. Returns None on malformed input. Complexity: O(n), n = string length.
toint.xi¶
fn to_int(n: Float64) -> Int¶
Truncates a float toward zero. Behavior for NaN and out-of-range values is undefined (use the checked/saturating variants for those inputs). Complexity: O(1).
fn to_int_saturating(f: Float64) -> Int¶
Truncates a float toward zero, clamping to INT_MAX/INT_MIN on overflow. NaN yields 0. Complexity: O(1).
fn to_int_checked(f: Float64) -> Option[Int]¶
Truncates a float toward zero only when the result fits an Int. Returns None for NaN or values outside [INT_MIN, INT_MAX). Complexity: O(1).
fn to_int_from_char(c: Char) -> Int¶
Returns a character's code point as an integer. Complexity: O(1).
tostring.xi¶
fn to_string(n: Int) -> Str¶
Formats an integer as a decimal string. Exact for the full Int range (including INT_MIN, which the core implementation mishandles by negating in place). Complexity: O(log_10 |n|).
fn to_string_float(f: Float64) -> Str¶
Formats a float as a string (15 significant digits, fixed or scientific, handling "nan" and "inf"). Complexity: O(|exp10| + 15).
fn to_string_bool(b: Bool) -> Str¶
Renders a boolean as "true" or "false". Complexity: O(1).
fn to_string_char(c: Char) -> Str¶
Renders a character as a single-character UTF-8 string. Complexity: O(1).
fn to_string_radix(n: Int, radix: Int) -> Str¶
Formats an integer in an arbitrary radix (2-36, lowercase digits). Returns "" for an invalid radix. Complexity: O(log_radix |n|).
tryfrom.xi¶
fn try_from_int(n: Int) -> Result[Float64, Str]¶
Widen an integer to a float only when the conversion is lossless. Parameters: n -- the integer value. Returns: Ok(Float64) when n fits exactly (|n| <= 2^53), Err otherwise. Complexity: O(1).
fn try_from_float(f: Float64) -> Result[Int, Str]¶
Truncate a float to an integer only when the value fits an Int. Parameters: f -- the float value. Returns: Ok(Int) for finite in-range values, Err for NaN or values outside the Int range. Complexity: O(1).
fn try_from_str(s: Str) -> Result[Int, Str]¶
Parse a string to an integer if valid. Parameters: s -- the decimal integer string (optional sign). Returns: Ok(Int) for well-formed input, Err otherwise. Complexity: O(n), n = string length.
unchecked.xi¶
fn unchecked_add(a: Int, b: Int) -> Int¶
a + b without overflow checking (wraps). Complexity: O(1).
fn unchecked_sub(a: Int, b: Int) -> Int¶
a - b without overflow checking (wraps). Complexity: O(1).
fn unchecked_mul(a: Int, b: Int) -> Int¶
a * b without overflow checking (wraps). Complexity: O(1).
fn unchecked_shl(a: Int, n: Int) -> Int¶
a << n without overflow checking (discards shifted-out bits); n is masked to [0, 64). Complexity: O(1).
fn unchecked_shr(a: Int, n: Int) -> Int¶
a >> n (arithmetic) without overflow checking; n is masked to [0, 64). Complexity: O(1).
uri.xi¶
type Uri¶
Uri -- parsed URI components.
| Field | Type |
|---|---|
scheme |
Str |
authority |
Str |
path |
Str |
query |
Str |
fragment |
Str |
fn uri_parse(s: Str) -> Result[Uri, Str]¶
Parse a URI into its scheme, authority, path, query and fragment. Parameters: s -- the URI string. Returns: Ok(Uri) on success; Err for an empty URI. Complexity: O(n).
fn uri_normalize(s: Str) -> Result[Str, Str]¶
Normalize a URI into canonical form: lowercase scheme, remove dot segments from the path, and keep the authority/query/fragment. Parameters: s -- the URI string. Returns: Ok(canonical) on success; Err for an empty URI. Complexity: O(n).
fn uri_resolve(base: Str, rel: Str) -> Result[Str, Str]¶
Resolve a relative URI against a base URI (RFC 3986 S5). Parameters: base -- the absolute base URI; rel -- the reference (may be absolute or relative). Returns: Ok(resolved) on success; Err when parsing fails. Complexity: O(n).
url.xi¶
type Url¶
Url -- parsed URL components.
| Field | Type |
|---|---|
scheme |
Str |
host |
Str |
port |
Int |
path |
Str |
query |
Str |
fn url_parse(s: Str) -> Result[Url, Str]¶
Parse a URL into its scheme, host, port, path and query components. Userinfo (user:pass@) is skipped. Parameters: s -- the URL string. Returns: Ok(Url) on success; Err for an empty URL or a missing host. Complexity: O(n).
fn url_build(scheme: Str, host: Str, port: Int, path: Str, query: Str) -> Str¶
Assemble a URL string from its parts. Parameters: scheme -- e.g. "https"; host -- e.g. "example.com"; port -- 0 means "no explicit port"; path -- must start with "/"; query -- the raw query string without '?' (empty means none). Returns: the assembled URL. Complexity: O(n).
fn url_encode(s: Str) -> Str¶
Percent-encode a URL (unreserved characters A-Z a-z 0-9 - _ . ~ pass through; everything else becomes %HH). Parameters: s -- the text to encode. Returns: the percent-encoded string. Complexity: O(n).
fn url_decode(s: Str) -> Result[Str, Str]¶
Percent-decode a URL. Parameters: s -- the encoded text. Returns: Ok(decoded) on success; Err for a truncated or invalid escape. Complexity: O(n).
urn.xi¶
fn urn_parse(s: Str) -> Result[(Str, Str, Str), Str]¶
Parse a URN into its (nid, nss, rq) components. Parameters: s -- the URN string. Returns: Ok((nid, nss, rq)) on success, where rq is the concatenation of the r-component and q-component ("" when absent); Err otherwise. Complexity: O(n).
fn urn_is_valid(s: Str) -> Bool¶
Check that a string is a valid URN. Parameters: s -- the candidate URN string. Returns: true when the URN structure is valid. Complexity: O(n).
fn urn_build(nid: Str, nss: Str) -> Str¶
Assemble a URN from a namespace identifier and specific string. Parameters: nid -- the namespace identifier (2-32 chars, alphanumeric plus hyphen, not starting or ending with hyphen); nss -- the namespace specific string. Returns: "urn:
: ". Complexity: O(n).
utf.xi¶
fn utf16_encode(s: Str) -> Vec[UInt16]¶
Encode a string to native-order UTF-16 code units (no BOM). Parameters: s -- the input string. Returns: UTF-16 code units (surrogate pairs for supplementary chars). Complexity: O(n).
fn utf16_decode(bytes: &Vec[UInt16]) -> Result[Str, Str]¶
Decode native-order UTF-16 code units to a string. Parameters: bytes -- the code units (a leading BOM is skipped). Returns: Ok(Str) on success; Err for lone surrogates. Complexity: O(n).
fn utf16le_to_bytes(s: Str) -> Vec[UInt8]¶
Encode a string to little-endian UTF-16 bytes including a BOM. Parameters: s -- the input string. Returns: the byte sequence. Complexity: O(n).
fn utf16be_to_bytes(s: Str) -> Vec[UInt8]¶
Encode a string to big-endian UTF-16 bytes including a BOM. Parameters: s -- the input string. Returns: the byte sequence. Complexity: O(n).
fn utf16_decode_le(bytes: &Vec[UInt8]) -> Result[Str, Str]¶
Decode little-endian UTF-16 bytes to a string. Parameters: bytes -- the byte sequence (a leading BOM is skipped). Returns: Ok(Str) on success; Err for an odd length or lone surrogates. Complexity: O(n).
fn utf16_decode_be(bytes: &Vec[UInt8]) -> Result[Str, Str]¶
Decode big-endian UTF-16 bytes to a string. Parameters: bytes -- the byte sequence (a leading BOM is skipped). Returns: Ok(Str) on success; Err for an odd length or lone surrogates. Complexity: O(n).
fn utf32_encode(s: Str) -> Vec[UInt32]¶
Encode a string to UTF-32 code points (no BOM). Parameters: s -- the input string. Returns: one UInt32 per code point. Complexity: O(n).
fn utf32_decode(code_points: &Vec[UInt32]) -> Result[Str, Str]¶
Decode UTF-32 code points to a string. Parameters: code_points -- the code points (a leading BOM is skipped). Returns: Ok(Str) on success; Err for a surrogate or out-of-range value. Complexity: O(n).
fn utf32le_to_bytes(s: Str) -> Vec[UInt8]¶
Encode a string to little-endian UTF-32 bytes including a BOM. Parameters: s -- the input string. Returns: the byte sequence. Complexity: O(n).
fn utf32be_to_bytes(s: Str) -> Vec[UInt8]¶
Encode a string to big-endian UTF-32 bytes including a BOM. Parameters: s -- the input string. Returns: the byte sequence. Complexity: O(n).
fn utf16_is_valid(s: Str) -> Bool¶
Report whether every code point of a string fits within UTF-16 (i.e. no character lies in the surrogate range and all are <= 0x10FFFF). Parameters: s -- the input string. Returns: true when every code point is encodable in UTF-16. Complexity: O(n).
fn utf32_is_valid(s: Str) -> Bool¶
Report whether a string contains no surrogate or invalid code points. Parameters: s -- the input string. Returns: true when every code point is a valid scalar value. Complexity: O(n).
fn code_point_to_utf16(cp: Int) -> (UInt16, UInt16)¶
Split a code point into a UTF-16 surrogate pair. Parameters: cp -- a code point >= 0x10000. Returns: (high surrogate, low surrogate). Code points below 0x10000 or above 0x10FFFF map to (0, 0). Complexity: O(1).
fn surrogate_pair_to_code_point(hi: UInt16, lo: UInt16) -> Int¶
Combine a UTF-16 surrogate pair into a code point. Parameters: hi -- the high surrogate; lo -- the low surrogate. Returns: the code point; -1 when the pair is not a valid surrogate pair. Complexity: O(1).
utf16.xi¶
fn utf16_encode(s: Str) -> Vec[UInt16]¶
Encode a string as UTF-16 code units (native order, no BOM). Parameters: s -- the input string. Returns: one UTF-16 code unit per BMP code point, surrogate pairs for supplementary characters. Complexity: O(n), n = code points.
fn utf16_decode(bytes: &Vec[UInt16]) -> Result[Str, Str]¶
Decode UTF-16 code units to a string. Parameters: bytes -- the code units (a leading BOM is skipped). Returns: Ok(Str) on success; Err for a lone surrogate, an invalid code unit range, or an overlong result. Complexity: O(n).
fn utf16le_to_bytes(s: Str) -> Vec[UInt8]¶
Encode a string as UTF-16LE bytes, including a BOM. Parameters: s -- the input string. Returns: the little-endian byte sequence. Complexity: O(n).
fn utf16be_to_bytes(s: Str) -> Vec[UInt8]¶
Encode a string as UTF-16BE bytes, including a BOM. Parameters: s -- the input string. Returns: the big-endian byte sequence. Complexity: O(n).
utf32.xi¶
fn utf32_encode(s: Str) -> Vec[UInt32]¶
Encode a string as UTF-32 code points (no BOM). Parameters: s -- the input string. Returns: one UInt32 per Unicode code point. Complexity: O(n), n = code points.
fn utf32_decode(code_points: &Vec[UInt32]) -> Result[Str, Str]¶
Decode UTF-32 code points to a string. Parameters: code_points -- the code points (a leading BOM is skipped). Returns: Ok(Str) on success; Err for a surrogate or out-of-range value. Complexity: O(n).
fn utf32le_to_bytes(s: Str) -> Vec[UInt8]¶
Encode a string as UTF-32LE bytes, including a BOM. Parameters: s -- the input string. Returns: the little-endian byte sequence. Complexity: O(n).
fn utf32be_to_bytes(s: Str) -> Vec[UInt8]¶
Encode a string as UTF-32BE bytes, including a BOM. Parameters: s -- the input string. Returns: the big-endian byte sequence. Complexity: O(n).
utf8.xi¶
fn utf8_encode(c: Char) -> Vec[UInt8]¶
Encode a character as UTF-8 bytes. Parameters: c -- the character. Returns: 1-4 bytes forming the UTF-8 encoding of c. Complexity: O(1).
fn utf8_decode(bytes: &Vec[UInt8]) -> Option[Char]¶
Decode one UTF-8 character from the start of a byte vector. Parameters: bytes -- a UTF-8 byte sequence. Returns: Some(Char) when the leading sequence is well-formed (including overlong/surrogate/range checks); None otherwise. Complexity: O(1).
fn utf8_validate(s: Str) -> Bool¶
Check that a string is well-formed UTF-8. Parameters: s -- the string to validate. Returns: true when every byte sequence decodes cleanly. Complexity: O(n), n = byte length.
fn utf8_valid_sequences(s: Str) -> Int¶
Count the valid UTF-8 sequences in a string. Invalid bytes advance one position without being counted. Parameters: s -- the string to scan. Returns: the number of well-formed UTF-8 sequences. Complexity: O(n), n = byte length.
uuencode.xi¶
fn uuencode(data: &Vec[UInt8]) -> Str¶
Encode arbitrary bytes to classic UU format (data lines only). Parameters: data -- the raw bytes. Returns: the UU-encoded text (each line ends with a newline). Complexity: O(n).
fn uudecode(s: Str) -> Result[Vec[UInt8], Str]¶
Decode a UU-encoded string to bytes. Parameters: s -- the UU text (data lines; "begin"/"end" wrappers ignored). Returns: Ok(bytes) on success; Err on malformed input. Complexity: O(n).
fn uuencode_line(data: &Vec[UInt8]) -> Str¶
Encode a single UU line of at most 45 bytes (length char + encoded data). Parameters: data -- up to 45 bytes. Returns: the encoded line (without a trailing newline). Complexity: O(1).
fn uudecode_line(s: Str) -> Result[Vec[UInt8], Str]¶
Decode a single UU line, validating length and padding. Parameters: s -- the encoded line (length char + data, no newline). Returns: Ok(bytes) on success; Err on invalid input. Complexity: O(1).
fn xxencode(data: &Vec[UInt8]) -> Str¶
Encode arbitrary bytes to XXencode format (data lines only). Parameters: data -- the raw bytes. Returns: the XX-encoded text. Complexity: O(n).
fn xxdecode(s: Str) -> Result[Vec[UInt8], Str]¶
Decode an XXencode string to bytes. Parameters: s -- the XX text. Returns: Ok(bytes) on success; Err on malformed input. Complexity: O(n).
fn uu_encoded_length(len: Int) -> Int¶
Compute the encoded length for a given input length: each 45-byte block becomes a 61-character line (60 data chars + newline). Parameters: len -- the input byte count. Returns: the UU-encoded text length. Complexity: O(1).
uuid.xi¶
fn uuid_v4() -> Str¶
Generate a random RFC 4122 version 4 UUID string (8-4-4-4-12, lowercase). Returns: a 36-character UUID string. Complexity: O(1).
fn uuid_parse(s: Str) -> Option[(Int, Int, Int, Int)]¶
Parse a UUID string into its four 32-bit fields. Parameters: s -- a UUID string in 8-4-4-4-12 form. Returns: Some((time_low, time_mid, time_hi_and_version, clock_and_node)) for a well-formed string, None otherwise. Complexity: O(1).
fn uuid_is_valid(s: Str) -> Bool¶
Check that a string is a valid UUID (36 chars, 8-4-4-4-12 layout, hex). Parameters: s -- the candidate string. Returns: true when the layout matches. Complexity: O(1).
fn uuid_v4_bytes() -> Vec[UInt8]¶
Generate the raw 16 bytes of a random RFC 4122 version 4 UUID. Returns: 16 bytes with the version (0100) and variant (10) bits set. Complexity: O(1).
validate.xi¶
fn is_valid_email(s: Str) -> Bool¶
Check the basic email shape (local@domain). Parameters: s -- the candidate address. Returns: true when there is exactly one '@', a non-empty local part, a non-empty domain containing a dot, and no whitespace. Complexity: O(n).
fn is_valid_email_strict(s: Str) -> Bool¶
Check an email against stricter RFC 5322-shaped rules: local part up to 64 chars, domain labels 1..63 chars, no leading/trailing dots. Parameters: s -- the candidate address. Returns: true for a well-formed address. Complexity: O(n).
fn is_valid_phone(s: Str) -> Bool¶
Check a phone number for a recognizable format (digits, spaces, + - ( )). Parameters: s -- the candidate number. Returns: true when the number contains 7..15 digits with only allowed separator characters. Complexity: O(n).
fn is_valid_phone_e164(s: Str) -> Bool¶
Check a phone number against the E.164 specification: optional leading '+', then 1..15 digits. Parameters: s -- the candidate number. Returns: true for an E.164-compliant number. Complexity: O(n).
fn is_valid_credit_card(s: Str) -> Bool¶
Check a card number for length (13-19 digits) and Luhn validity. Parameters: s -- the candidate card number (digits, optional spaces). Returns: true for a valid card number. Complexity: O(n).
fn luhn_check(s: Str) -> Bool¶
Validate a digit string with the Luhn algorithm. Parameters: s -- a string of digits. Returns: true when the Luhn checksum passes. Complexity: O(n).
fn is_valid_iban(s: Str) -> Bool¶
Validate an IBAN structure, country format, and mod-97 checksum. Parameters: s -- the candidate IBAN (spaces allowed). Returns: true for a valid IBAN. Complexity: O(n).
fn iban_country_code(s: Str) -> Str¶
Extract the two-letter country code from an IBAN. Parameters: s -- the IBAN. Returns: the country code (uppercase) or "" when too short. Complexity: O(1).
fn iban_checksum(s: Str) -> Str¶
Extract the two-digit checksum from an IBAN. Parameters: s -- the IBAN. Returns: the checksum digits or "" when too short. Complexity: O(1).
fn is_valid_swift(s: Str) -> Bool¶
Check a SWIFT/BIC code for the 8 or 11 character layout. Parameters: s -- the candidate code. Returns: true for a valid layout (6 alphanumeric + 2 alpha + optional 3 alphanumeric). Complexity: O(1).
fn is_valid_bic(s: Str) -> Bool¶
Alias checking a BIC code for the 8 or 11 character layout. Parameters: s -- the candidate BIC. Returns: true for a valid BIC. Complexity: O(1).
fn is_valid_hex_color(s: Str) -> Bool¶
Check a hex color value in #RGB, #RRGGBB, or #RRGGBBAA form. Parameters: s -- the candidate color. Returns: true for a well-formed hex color. Complexity: O(1).
fn is_valid_semver(s: Str) -> Bool¶
Check a semantic version string per SemVer 2.0.0 (major.minor.patch with optional -prerelease and +build). Parameters: s -- the candidate version. Returns: true for a valid SemVer. Complexity: O(n).
wrapping.xi¶
fn wrapping_add(a: Int, b: Int) -> Int¶
a + b, wrapping on overflow (two's complement). Complexity: O(1).
fn wrapping_sub(a: Int, b: Int) -> Int¶
a - b, wrapping on underflow. Complexity: O(1).
fn wrapping_mul(a: Int, b: Int) -> Int¶
a * b, wrapping on overflow. Complexity: O(1).
fn wrapping_neg(a: Int) -> Int¶
-a, wrapping on overflow (INT_MIN negates to itself). Complexity: O(1).
fn wrapping_abs(a: Int) -> Int¶
|a|, wrapping on overflow (INT_MIN maps to itself). Complexity: O(1).
fn wrapping_shl(a: Int, n: Int) -> Int¶
a << n with the shift amount masked to [0, 64); shifted-out bits are discarded. Complexity: O(1).
fn wrapping_shr(a: Int, n: Int) -> Int¶
a >> n (arithmetic) with the shift amount masked to [0, 64); shifted-out bits are discarded. Complexity: O(1).
wstring.xi¶
fn from_wstring(ptr: Int) -> Str¶
Convert a wide C string to a XIOM string. Parameters: ptr -- the address of the UTF-16 wide string (0 returns ""). Returns: the XIOM string. Complexity: O(n).
fn to_wstring(s: Str) -> Int¶
Allocate a wide-string copy of a XIOM string and return its pointer. Parameters: s -- the string to copy. Returns: a malloc'd UTF-16 pointer the caller must free. Complexity: O(n).
fn wstring_len(ptr: Int) -> Int¶
Length of a wide string in code units. Parameters: ptr -- the address of the UTF-16 wide string (0 returns 0). Returns: the number of code units before the terminating zero. Complexity: O(n).