Standard pieces
Generated from pieces/ (run python3 scripts/build-site.py). Import a default piece with use std.<name> and call it as <name>.function(...); community pieces are declared in [dependencies] and imported by name.
Default pieces
args
command-line argument parsing
use std.args · version 0.7.0
| function | description |
|---|---|
args_new() -> Args |
|
args_from(items: [string]) -> Args |
|
args_count(a: Args) -> int |
|
args_has_flag(a: Args, name: string) -> bool |
|
args_value(a: Args, name: string, dflt: string) -> string |
Value of --name value or --name=value, or dflt. |
args_positional(a: Args, value_flags: [string]) -> [string] |
Arguments that do not start with -, skipping the values of value_flags (flags taking a value). |
base64
Base64 encoding and decoding (RFC 4648)
use std.base64 · version 0.7.0
| function | description |
|---|---|
base64_alphabet() -> string |
|
base64_encode(s: string) -> string |
|
base64_value(c: int) -> int |
|
base64_decode(s: string) -> string |
"" on malformed input. |
bits
bit tricks on 64-bit ints: popcount, rotations, flags
use std.bits · version 0.7.0
| function | description |
|---|---|
bits_get(n: int, i: int) -> bool |
|
bits_set(n: int, i: int) -> int |
|
bits_clear(n: int, i: int) -> int |
|
bits_toggle(n: int, i: int) -> int |
|
bits_popcount(n: int) -> int |
|
bits_is_power_of_two(n: int) -> bool |
|
bits_next_pow2(n: int) -> int |
Smallest power of two >= n (n >= 1). |
bits_rotl32(x: int, k: int) -> int |
Rotate the low 32 bits left by k. |
bits_trailing_zeros(n: int) -> int |
Number of trailing zero bits (64 for 0). |
collections
stacks, queues, sets, sorting and list helpers for ints and strings
use std.collections · version 0.7.0
| function | description |
|---|---|
intstack_new() -> IntStack |
|
intstack_push(s: IntStack, x: int) |
|
intstack_pop(s: IntStack) -> int |
|
intstack_peek(s: IntStack) -> int |
|
intstack_len(s: IntStack) -> int |
|
intstack_is_empty(s: IntStack) -> bool |
|
intqueue_new() -> IntQueue |
|
intqueue_push(q: IntQueue, x: int) |
|
intqueue_pop(q: IntQueue) -> int |
|
intqueue_len(q: IntQueue) -> int |
|
intqueue_is_empty(q: IntQueue) -> bool |
|
strset_new() -> StrSet |
|
strset_add(s: StrSet, k: string) -> bool |
True when k was not in the set yet. |
strset_has(s: StrSet, k: string) -> bool |
|
strset_len(s: StrSet) -> int |
|
collections_sort_ints(xs: [int]) -> [int] |
---- int lists ------------------------------------------------------------------------------- A sorted copy (merge sort). |
collections_reverse_ints(xs: [int]) -> [int] |
|
collections_unique_ints(xs: [int]) -> [int] |
|
collections_index_of_int(xs: [int], x: int) -> int |
|
collections_contains_int(xs: [int], x: int) -> bool |
|
collections_slice_ints(xs: [int], from_i: int, to_i: int) -> [int] |
|
collections_concat_ints(a: [int], b: [int]) -> [int] |
|
collections_range_ints(a: int, b: int) -> [int] |
a, a+1, ..., b-1 |
collections_sum_ints(xs: [int]) -> int |
|
collections_min_int(xs: [int]) -> int |
|
collections_max_int(xs: [int]) -> int |
|
collections_sort_strings(xs: [string]) -> [string] |
|
collections_reverse_strings(xs: [string]) -> [string] |
|
collections_unique_strings(xs: [string]) -> [string] |
|
collections_index_of_string(xs: [string], x: string) -> int |
|
collections_contains_string(xs: [string], x: string) -> bool |
|
collections_slice_strings(xs: [string], from_i: int, to_i: int) -> [string] |
|
collections_concat_strings(a: [string], b: [string]) -> [string] |
crc32
CRC-32 checksum (IEEE 802.3)
use std.crc32 · version 0.7.0
| function | description |
|---|---|
crc32_of(s: string) -> int |
|
crc32_hex(s: string) -> string |
csv
CSV lines: parsing with quotes and writing
use std.csv · version 0.7.0
| function | description |
|---|---|
csv_parse_line(line: string, sep: string) -> [string] |
|
csv_quote(field: string, sep: string) -> string |
|
csv_join(fields: [string], sep: string) -> string |
datetime
calendar dates and times from Unix timestamps (UTC)
use std.datetime · version 0.7.0
| function | description |
|---|---|
datetime_is_leap(y: int) -> bool |
|
datetime_days_in_month(y: int, m: int) -> int |
|
datetime_floor_div(a: int, b: int) -> int |
Floor division (the C / truncates toward zero). |
datetime_days(secs: int) -> int |
|
datetime_year(secs: int) -> int |
|
datetime_month(secs: int) -> int |
|
datetime_day(secs: int) -> int |
|
datetime_hour(secs: int) -> int |
|
datetime_minute(secs: int) -> int |
|
datetime_second(secs: int) -> int |
|
datetime_weekday(secs: int) -> int |
0 = Sunday ... 6 = Saturday |
datetime_from_civil(y: int, m: int, d: int, hh: int, mm: int, ss: int) -> int |
Seconds since the epoch of a UTC date and time. |
datetime_pad2(n: int) -> string |
|
datetime_format_iso(secs: int) -> string |
"2026-11-14T10:30:00Z" |
datetime_weekday_name(w: int) -> string |
error
error handling: Error values with context chains and Result-like records
use std.error · version 0.7.0
| function | description |
|---|---|
error_none() -> Error |
|
error_new(code: int, message: string) -> Error |
|
error_is(e: Error) -> bool |
|
error_code(e: Error) -> int |
|
error_message(e: Error) -> string |
|
error_wrap(e: Error, context: string) -> Error |
Adds context in front of the message, keeping the code: "context: message". |
error_describe(e: Error) -> string |
|
error_fatal(e: Error) |
Prints the error to stdout and exits with its code (1 when the code is 0). |
result_int_ok(v: int) -> ResultInt |
|
result_int_err(e: Error) -> ResultInt |
|
result_int_is_ok(r: ResultInt) -> bool |
|
result_int_value(r: ResultInt) -> int |
|
result_int_error(r: ResultInt) -> Error |
|
result_str_ok(v: string) -> ResultStr |
|
result_str_err(e: Error) -> ResultStr |
|
result_str_is_ok(r: ResultStr) -> bool |
|
result_str_value(r: ResultStr) -> string |
|
result_str_error(r: ResultStr) -> Error |
|
result_bool_ok(v: bool) -> ResultBool |
|
result_bool_err(e: Error) -> ResultBool |
|
result_bool_is_ok(r: ResultBool) -> bool |
|
result_bool_value(r: ResultBool) -> bool |
|
result_bool_error(r: ResultBool) -> Error |
fmt
padding and number formatting
use std.fmt · version 0.7.0
| function | description |
|---|---|
fmt_pad_left(s: string, width: int) -> string |
|
fmt_pad_right(s: string, width: int) -> string |
|
fmt_zero_pad(n: int, width: int) -> string |
|
fmt_radix(n: int, base: int, upper: bool) -> string |
|
fmt_hex(n: int) -> string |
|
fmt_bin(n: int) -> string |
|
fmt_thousands(n: int) -> string |
1234567 -> "1,234,567" |
fmt_milli(v: int) -> string |
A value stored in thousandths, printed with 3 decimals: 1500 -> "1.500". |
fmt_bool(b: bool) -> string |
fs
files and directories
use std.fs · version 0.7.0
| function | description |
|---|---|
fs_exists(path: string) -> bool |
|
fs_read(path: string) -> string |
|
fs_write(path: string, text: string) -> bool |
|
fs_append(path: string, text: string) -> bool |
|
fs_copy(src: string, dst: string) -> bool |
|
fs_rename(src: string, dst: string) -> bool |
|
fs_temp_dir(prefix: string) -> string |
Entry names of a directory (including hidden ones, sorted). |
fs_is_dir(path: string) -> bool |
Directories answer access("<dir>/."); files do not. No shell involved (works on Windows too). A trailing slash only names a directory on every OS (Windows folds file/. into file, so that spelling cannot be used). |
fs_is_file(path: string) -> bool |
|
fs_mkdir_all(path: string) -> bool |
Creates path and its parents with the C library (no shell). |
fs_cwd() -> string |
|
fs_remove(path: string) -> bool |
|
fs_remove_all(path: string) -> bool |
|
fs_list(dir: string) -> [string] |
Entry names of a directory (including hidden ones). |
git
thin wrappers over the git command line
use std.git · version 0.7.0
| function | description |
|---|---|
git_available() -> bool |
|
git_clone(url: string, dir: string, tag: string) -> bool |
Shallow clone of tag (or the default branch when tag is "") into dir. |
git_fetch(dir: string) -> bool |
|
git_pull(dir: string) -> bool |
|
git_rev_parse(dir: string, rev: string) -> string |
Full commit hash of HEAD (or of rev), "" on failure. |
git_head(dir: string) -> string |
|
git_is_repo(dir: string) -> bool |
|
git_tags(dir: string) -> [string] |
|
git_remote_url(dir: string) -> string |
|
git_remote_tags(url: string) -> [string] |
git ls-remote --tags URL: tag names (without refs/tags/). |
glob
wildcard matching with * and ?
use std.glob · version 0.7.0
| function | description |
|---|---|
glob_match(pattern: string, text: string) -> bool |
|
glob_filter(pattern: string, names: [string]) -> [string] |
The names of names that match pattern. |
hex
hexadecimal encoding and decoding of byte strings
use std.hex · version 0.7.0
| function | description |
|---|---|
hex_digit_value(c: int) -> int |
|
hex_encode(s: string) -> string |
|
hex_decode(s: string) -> string |
"" when the text is not valid hex (odd length or a bad digit). |
hex_is_valid(s: string) -> bool |
http
HTTP requests through the curl command
use std.http · version 0.7.0
| function | description |
|---|---|
http_get(url: string) -> string |
|
http_post(url: string, body: string) -> string |
|
http_status(url: string) -> int |
HTTP status code (0 when the request could not be made). |
http_download(url: string, path: string) -> bool |
io
standard input and output helpers
use std.io · version 0.7.0
| function | description |
|---|---|
io_println(s: string) |
|
io_eprintln(s: string) |
|
io_read_all() -> string |
Everything on standard input. |
io_read_lines() -> [string] |
|
io_read_line() -> string |
iter
map, filter, reduce and friends over lists, with function values
use std.iter · version 0.7.0
| function | description |
|---|---|
iter_range(n: int) -> [int] |
The list 0, 1, ..., n-1. |
json
JSON value extraction without a tree
use std.json · version 0.7.0
| function | description |
|---|---|
json_skip_ws(t: string, i: int) -> int |
|
json_string_end(t: string, i: int) -> int |
Index just after the string literal that starts at i (t[i] == '"'). |
json_value_end(t: string, i: int) -> int |
Index just after the value that starts at i. |
json_unescape(s: string) -> string |
|
json_member_raw(t: string, key: string) -> string |
Raw JSON of member key of the object t ("" if t is not an object or has no such key). |
json_get_raw(t: string, path: string) -> string |
Raw JSON at a dotted path ("a.b.c"; array elements as numbers, "items.0.name"). |
json_is_index(s: string) -> bool |
|
json_get(t: string, path: string) -> string |
|
json_array(t: string) -> [string] |
Raw JSON of every element of the array t. |
json_quote(s: string) -> string |
log
leveled log lines on stdout with timestamps
use std.log · version 0.7.0
| function | description |
|---|---|
log_line(level: string, msg: string) -> string |
|
log_debug(msg: string) |
|
log_info(msg: string) |
|
log_warn(msg: string) |
|
log_error(msg: string) |
|
log_stamp() -> string |
|
log_info_ts(msg: string) |
|
log_error_ts(msg: string) |
math
floating point math (libm) and int/float conversion helpers
use std.math · version 0.7.0
| function | description |
|---|---|
math_sqrt(x: float) -> float |
|
math_pow(x: float, y: float) -> float |
|
math_sin(x: float) -> float |
|
math_cos(x: float) -> float |
|
math_tan(x: float) -> float |
|
math_atan2(y: float, x: float) -> float |
|
math_exp(x: float) -> float |
|
math_log(x: float) -> float |
|
math_floor(x: float) -> float |
|
math_ceil(x: float) -> float |
|
math_abs(x: float) -> float |
|
math_min(a: float, b: float) -> float |
|
math_max(a: float, b: float) -> float |
|
math_round(x: float) -> int |
Rounds to the nearest integer (halves away from zero). |
math_pi() -> float |
|
math_e() -> float |
mem
manual memory: typed buffers, realloc, copy and zero on top of alloc_n/realloc_n/copy_n/zero_n
use std.mem · version 0.7.0
| function | description |
|---|---|
mem_new(n: int) -> ptr<int> |
|
mem_free(p: ptr<int>) |
|
mem_get(p: ptr<int>, i: int) -> int |
|
mem_set(p: ptr<int>, i: int, v: int) |
|
mem_grow(p: ptr<int>, old: int, n: int) -> ptr<int> |
Resizes to n elements; new elements are zeroed, old is the previous element count. |
mem_copy(dst: ptr<int>, src: ptr<int>, n: int) |
|
mem_zero(p: ptr<int>, n: int) |
|
mem_fill(p: ptr<int>, n: int, v: int) |
|
mem_equal(a: ptr<int>, b: ptr<int>, n: int) -> bool |
|
intvec_new() -> IntVec |
|
intvec_push(v: IntVec, x: int) |
|
intvec_get(v: IntVec, i: int) -> int |
|
intvec_set(v: IntVec, i: int, x: int) |
|
intvec_pop(v: IntVec) -> int |
|
intvec_len(v: IntVec) -> int |
|
intvec_free(v: IntVec) |
option
Option
use std.option · version 0.7.0
path
string-based path helpers
use std.path · version 0.7.0
| function | description |
|---|---|
path_file_name(p: string) -> string |
std.path -- string-based path helpers (/ separated). Collapses ., .. and repeated separators. |
path_parent(p: string) -> string |
|
path_extension(p: string) -> string |
Extension without the dot ("" when there is none; ".bashrc" has none). |
path_stem(p: string) -> string |
|
path_with_extension(p: string, ext: string) -> string |
|
path_relative(p: string, root: string) -> string |
p relative to root when it lies below it, else p. |
path_has_extension(p: string) -> bool |
|
path_display(p: string, root: string) -> string |
p relative to root for display (an alias of path_relative, the name the compiler uses in messages). |
path_is_absolute(p: string) -> bool |
/x or a Windows drive path (C:/x). |
path_join(a: string, b: string) -> string |
|
path_norm(p0: string) -> string |
Collapses ., .. and repeated separators (a Windows drive prefix C: is kept). |
process
running programs and reading the environment
use std.process · version 0.7.0
| function | description |
|---|---|
process_run(cmd: string) -> int |
Exit code of the command (run through sh -c). |
process_output(cmd: string) -> string |
Standard output of the command. |
process_pid() -> int |
|
process_which(program: string) -> bool |
Whether program can be found on PATH. |
process_env(name: string) -> string |
random
pseudo-random numbers (xorshift64): ranges, shuffles, random strings
use std.random · version 0.7.0
| function | description |
|---|---|
random_new(seed: int) -> Rng |
|
random_from_clock() -> Rng |
|
random_next(r: Rng) -> int |
A non-negative integer. |
random_range(r: Rng, lo: int, hi: int) -> int |
lo <= n < hi |
random_bool(r: Rng) -> bool |
|
random_chance(r: Rng, percent: int) -> bool |
True percent times out of 100. |
random_shuffle(r: Rng, xs: [int]) -> [int] |
A shuffled copy (Fisher-Yates). |
random_string(r: Rng, n: int) -> string |
|
random_hex(r: Rng, n: int) -> string |
result
Result
use std.result · version 0.7.0
semver
semantic versions and requirements
use std.semver · version 0.7.0
| function | description |
|---|---|
semver_parse(text: string) -> Version |
|
semver_to_string(v: Version) -> string |
|
semver_cmp_pre(a: string, b: string) -> int |
Compares two pre-release strings by dot-separated identifiers (numeric < alphanumeric). |
semver_all_digits(s: string) -> bool |
|
semver_compare(a: string, b: string) -> int |
-1, 0 or 1. |
semver_satisfies(version: string, req: string) -> bool |
Requirements: "*", "1.2.3" (exact), "^1.2", "~1.2.3", ">=1.0", ">1", "<=2", "<2", "=1.2.3". |
semver_best(versions: [string], req: string) -> string |
Highest of versions that satisfies req ("" when none). |
sha256
SHA-256 hashing
use std.sha256 · version 0.7.0
| function | description |
|---|---|
sha_rotr(x: int, n: int) -> int |
|
sha_k() -> [int] |
|
sha_hex8(x: int) -> string |
|
sha256_hex(text: string) -> string |
stats
basic statistics over int lists: mean, median, variance, standard deviation
use std.stats · version 0.7.0
| function | description |
|---|---|
stats_sum(xs: [int]) -> int |
|
stats_mean(xs: [int]) -> float |
|
stats_median(xs: [int]) -> float |
|
stats_variance(xs: [int]) -> float |
|
stats_stddev(xs: [int]) -> float |
|
stats_min(xs: [int]) -> int |
|
stats_max(xs: [int]) -> int |
strings
string utilities: lines, chars, wrapping, counting, trimming, case
use std.strings · version 0.7.0
| function | description |
|---|---|
strings_lines(s: string) -> [string] |
|
strings_chars(s: string) -> [string] |
|
strings_reverse(s: string) -> string |
|
strings_count(s: string, sub: string) -> int |
Non-overlapping occurrences of sub. |
strings_last_index(s: string, sub: string) -> int |
|
strings_ltrim(s: string) -> string |
|
strings_rtrim(s: string) -> string |
|
strings_is_blank(s: string) -> bool |
|
strings_upper(s: string) -> string |
|
strings_lower(s: string) -> string |
|
strings_capitalize(s: string) -> string |
|
strings_title(s: string) -> string |
|
strings_pad_center(s: string, width: int) -> string |
|
strings_before(s: string, sep: string) -> string |
Text before / after the first sep ("" / the whole text when absent). |
strings_after(s: string, sep: string) -> string |
|
strings_replace_first(s: string, a: string, b: string) -> string |
|
strings_truncate(s: string, n: int, ellipsis: string) -> string |
s cut to n characters, ending with ellipsis when shortened. |
strings_wrap(text: string, width: int) -> [string] |
Greedy word wrap into lines of at most width characters. |
strings_join_ints(xs: [int], sep: string) -> string |
sys
libc hooks and shell helpers: the base of the other default pieces
use std.sys · version 0.7.0
| function | description |
|---|---|
sys_sh(cmd: string) -> int |
Runs a shell command and returns its exit code (-1 if it could not be started). |
sys_path_exists(path: string) -> bool |
Standard output of a shell command (stderr is discarded). |
sys_is_tty(fd: int) -> bool |
|
sys_pid() -> int |
|
sys_getenv(name: string) -> string |
Value of an environment variable ("" when unset). No shell involved. |
sys_is_windows() -> bool |
|
sys_null() -> string |
The null device: NUL on Windows, /dev/null elsewhere. |
sys_tmp_dir() -> string |
|
sys_quote(s: string) -> string |
Quotes one shell argument: single quotes for sh, double quotes for cmd.exe. |
sys_capture(cmd: string) -> string |
Standard output of a shell command (stderr is discarded). |
sys_eprint(s: string) |
Writes to standard error (unbuffered). |
sys_eprint_line(s: string) |
term
terminal colours and queries
use std.term · version 0.7.0
| function | description |
|---|---|
term_is_tty() -> bool |
|
term_esc() -> string |
The ESC byte, built at run time (so the seed compiler's lexer, which has no \x1b escape, can compile this too). |
term_paint_if(code: string, s: string, enabled: bool) -> string |
s wrapped in the SGR sequence code when enabled, else unchanged. |
term_is_tty_fd(fd: int) -> bool |
|
term_paint(code: string, s: string) -> string |
|
term_bold(s: string) -> string |
|
term_dim(s: string) -> string |
|
term_red(s: string) -> string |
|
term_green(s: string) -> string |
|
term_yellow(s: string) -> string |
|
term_blue(s: string) -> string |
|
term_cyan(s: string) -> string |
|
term_clear() -> int |
|
term_width() -> int |
Number of columns (80 when unknown). |
test
a tiny assertion library
use std.test · version 0.7.0
| function | description |
|---|---|
test_new(name: string) -> Tester |
|
test_ok(t: Tester, label: string) |
|
test_fail(t: Tester, label: string, detail: string) |
|
test_true(t: Tester, label: string, cond: bool) |
|
test_false(t: Tester, label: string, cond: bool) |
|
test_eq_int(t: Tester, label: string, actual: int, expected: int) |
|
test_eq_str(t: Tester, label: string, actual: string, expected: string) |
|
test_eq_bool(t: Tester, label: string, actual: bool, expected: bool) |
|
test_finish(t: Tester) -> int |
Prints the summary; returns the process exit code (0 = all passed). |
threads
threads: mutexes, atomics and sleeping on top of the spawn/thread_join builtins
use std.threads · version 0.7.0
| function | description |
|---|---|
mutex_new() -> int |
|
mutex_lock(m: int) |
|
mutex_unlock(m: int) |
|
mutex_free(m: int) |
|
atomic_new(initial: int) -> int |
An atomic integer: a mutex plus a value (handle = address of the block). |
atomic_get(a: int) -> int |
|
atomic_set(a: int, value: int) |
|
atomic_add(a: int, delta: int) -> int |
Adds delta and returns the new value. |
atomic_free(a: int) |
|
thread_sleep_ms(ms: int) |
|
thread_yield() |
time
clock, formatting and sleeping
use std.time · version 0.7.0
| function | description |
|---|---|
time_now_ms() -> int |
Nanoseconds since the Unix epoch. |
time_now_secs() -> int |
|
time_sleep_ms(ms: int) -> int |
|
time_format(fmt: string) -> string |
date format string, e.g. time_format("%Y-%m-%d %H:%M:%S"). |
time_elapsed_ms(start_ns: int) -> int |
Milliseconds elapsed since start_ns. |
time_fmt_secs(ns: int) -> string |
A nanosecond duration as seconds with two decimals: 1234000000 -> "1.23". |
time_now_ns() -> int |
Nanoseconds since the Unix epoch (C11 timespec_get: Linux, macOS and the Windows UCRT). |
toml
flat TOML reader
use std.toml · version 0.7.0
| function | description |
|---|---|
toml_unquote(s: string) -> string |
|
toml_get(text: string, section: string, key: string, dflt: string) -> string |
Value of key in section ("" for the top level); dflt when absent. |
toml_has(text: string, section: string, key: string) -> bool |
|
toml_get_int(text: string, section: string, key: string, dflt: int) -> int |
|
toml_keys(text: string, section: string) -> [string] |
Keys of a section, in file order. |
toml_quote(s: string) -> string |
|
toml_array_join(v: string) -> string |
["a", "b"] -> a, b (a plain value is just unquoted). |
toml_inline_get(v: string, key: string) -> string |
Value of key inside an inline table { a = "x", b = "y" } ("" if absent). |
toml_strip_comment(line: string) -> string |
Strips a trailing # comment that is not inside quotes. |
toml_quote_list(csv: string) -> string |
a, b -> ["a", "b"] |
types
number and character helpers: parsing, clamping, classification
use std.types · version 0.7.0
| function | description |
|---|---|
types_min(a: int, b: int) -> int |
|
types_max(a: int, b: int) -> int |
|
types_abs(a: int) -> int |
|
types_clamp(v: int, lo: int, hi: int) -> int |
|
types_sign(a: int) -> int |
|
types_is_even(a: int) -> bool |
|
types_gcd(a: int, b: int) -> int |
|
types_pow(base: int, exp: int) -> int |
|
types_is_int(s: string) -> bool |
True when s is an optionally signed decimal integer. |
types_parse_int(s: string, dflt: int) -> int |
Integer value of s, or dflt when it is not an integer. |
types_parse_bool(s: string, dflt: bool) -> bool |
"true"/"yes"/"1"/"on" -> true, "false"/"no"/"0"/"off" -> false, anything else -> dflt. |
types_is_upper(c: int) -> bool |
|
types_is_lower(c: int) -> bool |
|
types_to_upper(c: int) -> int |
|
types_to_lower(c: int) -> int |
|
types_upper(s: string) -> string |
|
types_lower(s: string) -> string |
|
types_isqrt(n: int) -> int |
Integer square root (floor). |
url
URL parsing and percent-encoding
use std.url · version 0.7.0
| function | description |
|---|---|
url_is_unreserved(c: int) -> bool |
|
url_encode(s: string) -> string |
|
url_hex_value(c: int) -> int |
|
url_decode(s: string) -> string |
+ becomes a space (form encoding). |
url_scheme(u: string) -> string |
|
url_authority(u: string) -> string |
Text after scheme:// up to the first /, ? or # (userinfo and port included). |
url_host(u: string) -> string |
|
url_port(u: string, dflt: int) -> int |
|
url_last_colon(a: string) -> int |
|
url_path(u: string) -> string |
|
url_query(u: string) -> string |
|
url_query_get(query: string, key: string, dflt: string) -> string |
Decoded value of key in a query string (a=1&b=two), or dflt. |
utf8
UTF-8 aware helpers: code point counting, validation, splitting
use std.utf8 · version 0.7.0
| function | description |
|---|---|
utf8_char_len(b: int) -> int |
utf8 -- strings are byte strings; these helpers look at them as UTF-8 text. Length in bytes of the character starting with lead byte b (1 for an invalid lead). |
utf8_len(s: string) -> int |
Number of code points. |
utf8_valid(s: string) -> bool |
|
utf8_chars(s: string) -> [string] |
Each code point as its own string. |
uuid
random (version 4) UUIDs
use std.uuid · version 0.7.0
| function | description |
|---|---|
uuid_v4(r: Rng) -> string |
|
uuid_is_valid(s: string) -> bool |
Community pieces
diff
line-by-line text differences (LCS)
use diff · version 0.1.0
| function | description |
|---|---|
diff_lines(a: [string], b: [string]) -> [string] |
|
diff_changed(a: [string], b: [string]) -> bool |
ini
read INI configuration text
use ini · version 0.1.0
| function | description |
|---|---|
ini_strip(line: string) -> string |
|
ini_get(text: string, section: string, key: string, dflt: string) -> string |
|
ini_sections(text: string) -> [string] |
|
ini_keys(text: string, section: string) -> [string] |
progress
text progress bars
use progress · version 0.1.0
| function | description |
|---|---|
progress_bar(done: int, total: int, width: int) -> string |
table
plain-text tables with aligned columns
use table · version 0.1.0
| function | description |
|---|---|
table_new(cols: int) -> Table |
|
table_add_row(t: Table, row: [string]) |
|
table_rows(t: Table) -> int |
|
table_widths(t: Table) -> [int] |
|
table_render(t: Table) -> string |
Rows separated by newlines, columns by two spaces, the first row underlined. |