ES
Standard Library20 std/* Modules

Text, Parse, JSON & CSV

Standard library reference for std/text (Unicode 16.0.0 UAX

std/text — UTF-8 Strings & Unicode Normalization

Section titled “std/text — UTF-8 Strings & Unicode Normalization”

Provides string slicing/query utilities plus Unicode 16.0.0 UAX #15 canonical normalization (normalize_nfc, normalize_nfd, canonical_equal).

Function Signature Purpose
split / join split(s, sep) -> list[str] / join(parts, sep) -> str Split and join string lists
lines lines(s) -> list[str] Split on LF or CRLF
trim / trim_start / trim_end trim(s) -> str Strip ASCII whitespace
to_lower / to_upper to_lower(s) -> str ASCII case conversion
contains / starts_with / ends_with contains(haystack, needle) -> bool Substring/affix probes
find find(haystack, needle) -> int? Codepoint offset (none if absent)
replace / repeat / pad_left replace(s, target, repl) -> str Text transformation helpers
normalize_nfc / normalize_nfd normalize_nfc(s) -> str UAX #15 canonical normalization
canonical_equal canonical_equal(a, b) -> bool Unicode canonical equivalence check

Safe numeric parsing returning T ! ParseError with whitespace trimming, sign handling, and 64-bit overflow detection:

from std.parse use { parse_int, parse_float }
fn main() -> unit {
let port = parse_int(" 8080 ") else err {
print(f"Bad port: {err.message}")
80
}
let ratio = parse_float("3.14159") else _ { 0.0 }
print(f"port={port}, ratio={ratio}")
}

std/json — Bounded JSON Parser & Serializer

Section titled “std/json — Bounded JSON Parser & Serializer”

std/json parses untrusted JSON safely using strict memory and depth budgets (defaults: 1 MiB input, depth 32, 100,000 nodes), preserves exact numeric spelling as strings to prevent silent float precision loss, and serializes compact deterministic JSON with keys sorted by Unicode scalar value.

import "std/json"
fn read_port(raw: str) -> int ! json.JsonError {
let doc = json.parse(raw)?
return json.get_int(doc, "port")?
}

Key APIs (qualify types as json.Value / json.JsonError when importing import "std/json"):

  • Parsing: json.parse(text) -> json.Value ! json.JsonError and json.parse_with_limits(text, max_bytes, max_depth, max_nodes) (max_bytes: 1..16777216).
  • Serialization: json.stringify(value) -> str ! json.JsonError.
  • Constructors: null(), boolean(bool), number(str), string(str), array(list[json.Value]), object(dict[str, json.Value]), plus convenience helpers from_int, from_float, from_bool, from_str.
  • Optional accessors (-> T?, unwrap with ??): is_null, as_bool, as_number, as_string, as_array, as_object, get(val, key), at(val, idx).
  • Typed Result extractors (-> T ! json.JsonError, unwrap with ? or else err { ... }, never ??): to_str, to_bool, to_int, to_float, to_array, to_object, get_required, get_str, get_int, get_float, get_bool, and get_optional_* with structured path diagnostics (e.g. status_code: expected JSON integer, found JSON string).

std/csv — Pure-Wysna RFC 4180 CSV (v0.8.0)

Section titled “std/csv — Pure-Wysna RFC 4180 CSV (v0.8.0)”

Parses and serializes RFC 4180 CSV with quoted fields, "" escapes, and embedded newlines:

import "std/csv"
fn load_rows(source: str) -> list[dict[str, str]] ! csv.CsvError {
return csv.parse_records(source)
}
  • csv.parse(source) -> list[list[str]] ! CsvError — raw rows.
  • csv.parse_records(source) -> list[dict[str, str]] ! CsvError — rows keyed by header column names; rejects column-count mismatches with CsvError.
  • csv.stringify(rows) -> str ! CsvError — escapes commas, quotes, and newlines deterministically.