Module
std.str — the documented API surface of the language's str: an immutable, guaranteed-valid UTF-8 slice, two machine words wide (D24). Stability tier: core.
What is the language's and what is std's (the API-CONVENTIONS §8 question, asked again for strings). The language owns:
- every literal — every string literal is an f-string, {x} interpolates, {{/}} escape, """ dedents by the closing delimiter's column, r"…" is raw ([gram.lex.str], D26/X9); - s.len — the length in BYTES, O(1) (D25); - s[a..b] — zero-copy byte-offset slicing, checked: an out-of-range offset OR an offset inside a code point traps bounds ([conf.trap.set]), deterministically, in every profile; - the relational family — ==, !=, <, <=, >, >=, <=> are byte-lexicographic over the UTF-8 bytes ([mem.str.order], the ruling this repo's F-0006 asked for); - the builtin method set this file delegates to, which is now the whole s37 set: is_empty, get, bytes, contains, starts_with, ends_with, find, rfind, count, split, words, each_word, words_count, lines, trim, trim_start, trim_end, lower, upper, strip_prefix, strip_suffix, repeat, replace.
Everything else is std's — this file. Functions take the string as their first parameter with the bare read mode, because str is immutable and nothing here mutates: the builder is std.strbuf.
NO CHAR INDEXING, and no negative indices (D25). There is no s[i]: a byte offset is the one honest currency, so find returns offsets and char_offsets yields them. To reach the first code point, slice (s[..n]) or ask get for a range it may refuse. ^n end-relative indexing (s[..^1]) is the language's spelling for the other end, and it RESOLVES ON ALL THREE LANES as of the sc24 pins (lupin 0.1.14, wolf @ a900b8c; re-measured at both sc24 wolf acquisitions) — F-0018's last living clause, healed: every from-end form slices byte-counted from the end, and one that lands inside a code point traps bounds like any other split (tests/str/end_relative_slice.lu and its trap twin hold both claims). The one residue is the RANGE get consumes: s.get(0..^1) runs under lupin and is unsupported at resolve on both wolf rungs, against [mem.str.get]'s own sentence that end-relative endpoints resolve exactly as in s[a..b] (F-0096, filed; re-measured verbatim AGAIN at the sc32 pin v0.2.2/8cda3aa, 2026-09-02 — "open-ended or end-relative ranges (slicing)" at resolve on both rungs, @103..108, lupin runs. v0.2.2 is a windows native bring-up, an LSP navigation trio, the region ledger and its cap, D69's comma tightening and four letters, and none of them is the get lowering; the sc31 reading at v0.2.1/75fd2d0 it replaces was byte-identical; re-measured verbatim AGAIN at the sc34 pin 0.2.3+dev.31170d1, 2026-09-02 — the first re-probe against a MOVING compiler in three sprints, 51 commits including a whole new scalar type, and the refusal is the same word at the same phase; tests/str/end_relative_get.lu is the row that flips at its closure). There is deliberately no std function that papers over either spelling.
THE BOUNDARY PRIMITIVE LANDED, AND THIS MODULE IS WHAT IT BOUGHT. For five sprints fifteen of this module's functions were reviewed contracts with no bodies, because every position-taking string algorithm needs a way to ask "is offset k a code-point boundary?" and the only way to ask was to slice at k — which TRAPS when the answer is no, uncatchably (D30, no unwinding). s37 shipped the recoverable slice s.get(a..b) -> str ! {none} ([mem.str.get]) plus find/rfind/ split/count/ends_with/strip_suffix/replace and the byte view s.bytes() -> List[byte], and all three lanes execute them (wolfc at s37, lupin at 0.1.5, native at #40). Twelve of the fifteen are code below — THIRTEEN as of sc24: D58 ruled the char type ([type.char], a Unicode scalar value — ordered, NOT an integer) and the sc24 wolf pair executes it, so to_list_chars is code at last — on ALL executing lanes as of sc25: lupin 0.1.15 (the is26 scalar release) runs chars() and char, and the rows that were ledgered by lane flipped at that release, as their comments promised. The sprint's own first measurement is worth a sentence here: the FIRST sc24 wolf acquisition (@ e7abf03) carried s120 without s121, spoke chars() in the v0 List[int] currency, and refused 'a' at lex — a mid-sprint re-acquisition brought s121, and every claim in this header was re-measured against the binary that will be pinned. What remains is two:
chars(s: str) -> List[(int, char)]
Code points with their byte offsets. The value half is ruled and
executable (D58; `to_list_chars` below); the PAIR still needs a
`List` of tuples on the wolf rungs (`List[(int, int)]`
re-measured `unsupported` at resolve at BOTH sc24 wolf
acquisitions, and AGAIN at the sc27 pin 0a5c1af — s128's tuple
work is destructuring/patterns and does not instantiate a tuple
LIST; same "prelude container instantiation" refusal, dated
2026-08-29; re-measured verbatim at the sc28 pin v0.2.0/c88ab64,
2026-08-30; re-measured verbatim at the sc30 pin b80d239, the
FOURTH consecutive pin, 2026-08-31 — s129/s130 are struct
patterns and product match arms, and neither instantiates a
tuple list either; re-measured verbatim AGAIN at the sc31 pin
v0.2.1/75fd2d0, the FIFTH consecutive pin, 2026-09-01 — r04 is
four measured letters, `defer` timing, the `\u{…}` bound and
two region diagnostics, and container instantiation is none of
them; and AGAIN at the sc32 pin v0.2.2/8cda3aa, the **SIXTH**
consecutive pin, 2026-09-02 — same word verbatim, `@72..90`,
lupin runs it. v0.2.2 is the largest span this repo has ever
crossed in one bump — a windows native bring-up, an LSP
navigation trio, the whole region ledger and cap, D69 and four
letters — and not one commit in it lowers a generic container
instantiation. Re-measured verbatim at the sc33 pin
(the SEVENTH) and AGAIN at the sc34 pin 0.2.3+dev.31170d1,
the **EIGHTH** consecutive pin, 2026-09-02 — and the eighth is
the one that counts, because the wolf binary moved 51 commits
under it (s60b, s134, r06, s135 and D72's whole `byte` type)
where sc33's binary had not moved at all. Eight pins is long
enough to state the shape plainly: this refusal never moves as
a SIDE EFFECT, and it will move the sprint someone lowers
generic container instantiation on purpose). `char_offsets` below is the offset
half; the
day tuple lists land they fuse into this one function.
graphemes(s: str) -> List[str]
Extended grapheme clusters, as slices of `s`. A std call and never
the default unit (D24). Needs segmentation TABLES — a later tier
(the #18 ruling put the data in committed generated wolf source
when it comes) and not a primitive gap: nothing about this pin's
`str` brings it closer, and sc24 deliberately does not start it.
THE BYTE VIEW IS A VIEW NOW, AND FOUR BODIES HERE ARE WRITTEN AGAINST THAT (s77 / wolf-lang#80, the sc12 pin). s.bytes() is the receiver's own pointer and length — bit-identical to the str and to every zero-copy subslice trim/split/get already returned. Lowering reads that pair wherever the call is CONSUMED, so a byte walk emits no call and no allocation; s[a..b] and s.get(a..b) stopped calling the runtime in the same wave.
std used TWO of those consuming positions for two sprints because the other five cost a lane, and at the sc12 pin the constraint is GONE (F-0071 CLOSED by s88's #85, "a temporary can be read from" — re-measured shape by shape: s.bytes()[i], .get(i), .first(), .last() and .count() all execute on wolfc's checked tier now, where every one of them was unsupported at mem). The walks below did not change back, and that is a decision rather than an oversight: the one-pass state machine code_points became is SHORTER than the random-access walk it replaced, and a constraint that forced a better algorithm is not one to undo the day it lifts. What the closure buys is that a future body may index a view without paying a lane for it. The rule it was an instance of stands unchanged: a shape that costs a lane is not a shape std writes (§14's honesty, applied to an optimization rather than to a capability). lupin still has no first on a List, measured at this pin, so that one position is still not portable.
What changed for this module is four bodies and no signature. char_count, char_offsets, code_points and is_ascii were written in sc09 as let bs = s.bytes() plus a walk over bs, which was the only shape available when the builtin materialized a List[int] per call. Nothing a caller can see moved: same answers, same rows, same lanes, and tests/str/code_point_view.lu is what says so.
The boundary of the win is a function boundary, and it is worth stating where a reader will meet it: every position that is NOT consuming — a let binding, an argument, a return — materializes exactly as before. So str.bytes(s) below still allocates (it returns the list), std.bytes' functions still take a materialized List[int], and a std function cannot pass a view to a helper. The win lives inside one body today, which is why this sprint's work was rewriting bodies and not signatures.
THE EMPTY NEEDLE IS RULED, AND STD'S GUARDS ARE GONE ([mem.str.empty], wolf-lang#56, F-0055 CLOSED at the sc11 pin). For three sprints count(""), split("") and replace(s, "", …) were undefined and the three lanes disagreed — two refused the call as unsupported, the native runtime answered — so six functions here guarded the empty argument and two of them TRAPPED, which was std stating a contract the toolchain had not stated. s71 states it: an empty needle counts 0, splits to one whole piece, and replaces nothing (identity). Measured on all three lanes at this pin, so count, split and replace simply delegate now, and the functions std writes itself agree with the ruling by construction: splitn answers the one whole piece, rsplit inherits split's, replacen is the identity. Nothing in this module traps on an empty argument any more. The find-defined family (split_once, rsplit_once, find_all) inherits find's answer instead, and says so on itself.
**PADDING LIVES IN std.fmt** (§11: the format spec is a spelling and std owns the operations). pad_left, pad_right, center, their _with fill variants and with_sign are std.fmt's, not this module's — one concept, one name, one home (§1). This module has no width family and will not grow one; when display width (East Asian Width plus graphemes) becomes computable it arrives under its own name in the module that owns the tables.
THE PARSE FAMILY MOVED (sc05). parse_int and parse_float were shipped here by sc03 because this is where the boundary-safe probe was proven; the sprint that owns PRINTING numbers owns the whole number↔text boundary, so they now live in std.fmt and std.fmt.decimal beside to_str_base and to_str, where a reader can see the two directions as inverses and a test can hold them to it. Two behaviours improved in the move: a radix outside 2..36 raises base rather than parse, and parse_float is correctly rounded rather than "honest but approximate". Nothing in std.str calls them, so this module no longer carries a digit table at all.
The unicode posture, written down (the sprint's filed decision). What ships in v1: UTF-8 validity as a type invariant (the language's), byte-offset slicing that refuses to split a code point (the language's), and ASCII-true classification named as such (std.unicode, over the int code points code_points now produces). What is NOT here and is a budget decision filed upstream, not a silent gap: category tables, full case mapping, normalization, and grapheme segmentation data. The evidence: the implementations' lower/upper already perform SIMPLE UNICODE case mapping ("ÉA".lower() is "éa", observed on every lane), which is MORE than the sprint contract promised and means the tables are already being carried somewhere — so the decision to make is where they live and who pays for them, not whether to start (F-0018, with std.unicode's posture).
Functions and methods
fn · Source line 228
pub fn len(s: str) -> int
The length of s in BYTES, O(1) — the honest unit (D25). This is the documented byte-length test the sprint asks for: a two-byte code point has length 2, and the number of CODE POINTS is a different question that char_count answers. Total: no error row, no traps.
str.len("wolf") == 4
str.len("é") == 2
str.len("🐺") == 4
str.len("") == 0
fn · Source line 238
pub fn is_empty(s: str) -> bool
Whether s holds no bytes. Total: no error row, no traps.
str.is_empty("") == true
str.is_empty("wolf") == false
fn · Source line 265
pub fn get(s: str, from: int, to: int) -> str ! {none}
The bytes in [from, to) — the RECOVERABLE slice, and the primitive the rest of this module is written over ([mem.str.get], D25's anti-landmine form). none when the range is out of order, out of range, or would split a code point: the one function that ANSWERS the boundary question where s[from..to] faults on it. Never traps.
Spelled with two offsets rather than a range because a range value crossing a std function boundary is not something every lane types (F-0030); the builtin takes the range and this wrapper builds it.
Use get when the offsets are DATA (a caller's input, an offset from another source) and s[from..to] when they are yours by construction — an offset find returned is a boundary and a trap there would be a bug, not a fault.
(str.get("héllo", 0, 3) else "?") == "hé"
(str.get("héllo", 0, 2) else "?") == "?"
(str.get("héllo", 1, 2) else "?") == "?"
(str.get("héllo", 0, 99) else "?") == "?"
(str.get("héllo", 3, 1) else "?") == "?"
(str.get("héllo", 0, 0) else "?") == ""
fn · Source line 293
pub fn bytes(s: str) -> List[byte]
The raw bytes of s, in order, as the 0..255 element values §11's interim byte currency uses — std.bytes is the module that operates on them and bytes.from_str is the same view from that side. Total: no error row, no traps beyond allocation.
**This function allocates and the language's s.bytes() no longer does, and the difference is the whole s77 story.** A byte view is the receiver's own pointer and length, read in place wherever it is CONSUMED — for b in s.bytes(), s.bytes()[i], s.bytes().len and the small query family — and materialized in every other position, which includes being RETURNED from a function like this one. So this wrapper is the honest to_-grade copy its name reserves the right to be (§1), and the fast path is the language's own spelling inside one body. std's own walks (char_count, char_offsets, code_points, is_ascii) stopped calling this function in sc12 for exactly that reason; a caller who wants the list — to keep it, to pass it to std.bytes, to hold it past s — still wants this.
var n = 0
for b in str.bytes("hé") { n = n + b }
n = n + 0
n == 468
fn · Source line 306
pub fn contains(s: str, needle: str) -> bool
Whether needle occurs anywhere in s, as a byte sequence. The empty needle occurs in every string, including the empty one. Total: no error row, no traps.
str.contains("the wolf runs", "wolf") == true
str.contains("the wolf runs", "moon") == false
str.contains("", "") == true
fn · Source line 324
pub fn find(s: str, needle: str) -> int ! {none}
The byte offset of the FIRST occurrence of needle in s; none when it does not occur. The empty needle occurs at 0. Total otherwise: a needle longer than s is a miss, not a fault, and no input traps.
The offset is a code-point boundary of s by construction, so slicing at it is safe — which is what makes split_once, find_all, replacen and splitn writable below.
(str.find("the wolf runs", "wolf") else 0 - 1) == 4
(str.find("the wolf runs", "moon") else 0 - 1) == 0 - 1
(str.find("héllo", "l") else 0 - 1) == 3
(str.find("wolf", "") else 0 - 1) == 0
fn · Source line 339
pub fn rfind(s: str, needle: str) -> int ! {none}
The byte offset of the LAST occurrence of needle in s; none when it does not occur. The empty needle occurs at len(s) — the end, which is what "last" means for something that occurs everywhere. Total otherwise: no traps.
(str.rfind("a/b/c", "/") else 0 - 1) == 3
(str.rfind("a/b/c", "x") else 0 - 1) == 0 - 1
(str.rfind("héllo", "l") else 0 - 1) == 4
(str.rfind("wolf", "") else 0 - 1) == 4
fn · Source line 360
pub fn find_all(s: str, needle: str) -> List[int]
The byte offsets of every NON-OVERLAPPING occurrence of needle, left to right — the find-all family's one member, and the plural of find rather than a new vocabulary. count(s, needle) is its length.
The empty needle yields no offsets, for count's reason — count is this function's length and the ruled count of nothing is 0 ([mem.str.empty]). The guard is also what makes the loop terminate: find("") is 0 at every step, so a body that advanced by the needle's length would not advance at all. Allocates the list. Total: no error row, no traps beyond allocation.
var n = 0
for at in str.find_all("a,b,c", ",") { n = n + at }
n = n + 0
n == 4
fn · Source line 395
pub fn count(s: str, needle: str) -> int
The number of NON-OVERLAPPING occurrences of needle in s, scanning left to right — "aaa" contains one "aa", not two. The empty needle counts 0, not len + 1: a count of nothing is nothing, which was this module's reviewed contract and is now the language's ruling ([mem.str.empty]), so the guard std carried for three sprints is gone and the delegation says the same thing. Total: no error row, no traps.
str.count("a,b,c", ",") == 2
str.count("aaa", "aa") == 1
str.count("wolf", "z") == 0
str.count("wolf", "") == 0
fn · Source line 411
pub fn starts_with(s: str, prefix: str) -> bool
Whether s begins with prefix. The empty prefix always matches. Total: no error row, no traps.
When it answers true, len(prefix) is a code-point boundary of s — the property sc03 built this module's first bodies on, kept here because it is still the cheapest way to reason about an offset.
str.starts_with("wolf-lang", "wolf") == true
str.starts_with("wolf-lang", "lang") == false
str.starts_with("🐺!", "🐺") == true
fn · Source line 424
pub fn ends_with(s: str, suffix: str) -> bool
Whether s ends with suffix. The empty suffix always matches. Total: no error row, no traps.
str.ends_with("wolf.lu", ".lu") == true
str.ends_with("wolf.lu", ".rs") == false
str.ends_with("a🐺", "🐺") == true
str.ends_with("wolf", "") == true
fn · Source line 441
pub fn starts_with_any(s: str, prefixes: List[str]) -> bool
Whether s begins with ANY of prefixes — the set form of starts_with, for the switch a parser writes over a keyword list. An empty list matches nothing; an empty prefix IN the list matches everything, exactly as starts_with does. Total: no error row, no traps.
var ps = List[str]()
(mut ps).push("http://")
(mut ps).push("https://")
str.starts_with_any("https://wolf.lang", ps) == true
str.starts_with_any("ftp://wolf.lang", ps) == false
fn · Source line 465
pub fn ends_with_any(s: str, suffixes: List[str]) -> bool
Whether s ends with ANY of suffixes — the set form of ends_with, for the extension test a file walker writes. An empty list matches nothing. Total: no error row, no traps.
var ss = List[str]()
(mut ss).push(".lu")
(mut ss).push(".wolfi")
str.ends_with_any("main.wolfi", ss) == true
str.ends_with_any("main.rs", ss) == false
fn · Source line 487
pub fn strip_prefix(s: str, prefix: str) -> str ! {none}
s without a leading prefix; none when s does not start with it — the absence row rather than s unchanged, so the caller can tell the two apart (§2). Consumed by else or ?. No traps.
(str.strip_prefix("wolf-lang", "wolf-") else "?") == "lang"
(str.strip_prefix("wolf-lang", "lang") else "?") == "?"
(str.strip_prefix("wolf", "") else "?") == "wolf"
fn · Source line 500
pub fn strip_suffix(s: str, suffix: str) -> str ! {none}
s without a trailing suffix; none when it is not there — the absence row for strip_prefix's reason (§2). Consumed by else or ?. No traps.
(str.strip_suffix("main.lu", ".lu") else "?") == "main"
(str.strip_suffix("main.lu", ".rs") else "?") == "?"
(str.strip_suffix("wolf", "") else "?") == "wolf"
fn · Source line 524
pub fn split(s: str, sep: str) -> List[str]
Every piece of s between occurrences of sep, in order, keeping empty pieces: split("a,,b", ",") is three pieces and split("", ",") is one empty piece. The pieces are slices of s; the list allocates.
An empty sep yields ONE piece — the whole of s — which is the language's ruling ([mem.str.empty]) and not this module's choice: there is no boundary anywhere, so there is nothing to cut. std guarded this with a trap while the three lanes disagreed about it (F-0055, closed at the sc11 pin); the guard is gone and the delegation is the contract. No traps.
var n = 0
for p in str.split("a,,b", ",") { n = n + 1 }
n = n + 0
n == 3
let whole = str.split("a,b", "")
whole.len == 1
whole[0] == "a,b"
fn · Source line 548
pub fn splitn(s: str, sep: str, n: int) -> List[str]
split stopping after n pieces: at most n are produced and the LAST one keeps the whole unsplit remainder, separators and all. n <= 0 produces no pieces at all — the honest reading of "at most n" — and n == 1 is the whole string as one piece.
An empty sep yields the whole of s as one piece for any n >= 1, which is split's ruled answer truncated to at most n ([mem.str.empty]) — the guard below states it explicitly because this body walks find rather than delegating, and find("") is 0 forever. Allocates the list; the pieces are slices of s. No traps.
var n = 0
for p in str.splitn("a,b,c", ",", 2) { n = n + 1 }
n = n + 0
n == 2
let whole = str.splitn("a,b", "", 3)
whole.len == 1
whole[0] == "a,b"
fn · Source line 588
pub fn rsplit(s: str, sep: str) -> List[str]
split's pieces in REVERSE order — last piece first. The pieces themselves are not reversed and no byte moves: only the list order differs, so rsplit(s, sep) and split(s, sep) always have the same length and the same members.
An empty sep yields split's one whole piece, in a list of one, where order cannot matter ([mem.str.empty]). Allocates the list. No traps.
var first = "?"
for p in str.rsplit("a,b,c", ",") { first += p }
first == "?cba"
fn · Source line 616
pub fn split_once(s: str, sep: str) -> (str, str) ! {none}
The pieces of s before and after the FIRST occurrence of sep; none when sep does not occur — the pair is only meaningful together, so absence is one row and not two empty strings (§2).
The empty separator occurs at 0 (find's contract), so split_once(s, "") is ("", s) rather than a trap: unlike split there IS a well-defined answer, and this function's only obligation is to agree with find. Both pieces are slices of s. No traps.
let p = str.split_once("key=value=more", "=") else ("?", "?")
p.0 == "key"
p.1 == "value=more"
let q = str.split_once("nosep", "=") else ("?", "?")
q.0 == "?"
fn · Source line 639
pub fn rsplit_once(s: str, sep: str) -> (str, str) ! {none}
split_once at the LAST occurrence of sep: the pieces before and after it, or none when it does not occur. The empty separator occurs at len(s) (rfind's contract), so rsplit_once(s, "") is (s, ""). Both pieces are slices of s. No traps.
This is the extension-and-stem shape: rsplit_once("archive.tar.gz", ".") is ("archive.tar", "gz"), where split_once would have given ("archive", "tar.gz").
let p = str.rsplit_once("archive.tar.gz", ".") else ("?", "?")
p.0 == "archive.tar"
p.1 == "gz"
let q = str.rsplit_once("nodot", ".") else ("?", "?")
q.1 == "?"
fn · Source line 665
pub fn replace(s: str, old: str, new: str) -> str
A fresh string with every NON-OVERLAPPING occurrence of old replaced by new, left to right, allocated in the ambient region. Scanning resumes AFTER each replacement, so replace("aaa", "aa", "b") is "ba" and a new that contains old does not feed itself.
An empty old replaces NOTHING — the result is s — which is the language's ruling ([mem.str.empty]): an empty pattern occurs everywhere and at no width, so inserting new at every position would be a different operation with a different name. std trapped here while the lanes disagreed (F-0055, closed at the sc11 pin) and delegates now. No traps.
str.replace("a,b,c", ",", ";") == "a;b;c"
str.replace("aaa", "aa", "b") == "ba"
str.replace("wolf", "z", "y") == "wolf"
str.replace("héllo", "l", "L") == "héLLo"
str.replace("a,b", "", "-") == "a,b"
fn · Source line 682
pub fn replacen(s: str, old: str, new: str, n: int) -> str
replace stopping after n replacements; the rest of s is copied unchanged. n <= 0 replaces nothing and returns s.
An empty old is the identity for any n, which is replace's ruled answer ([mem.str.empty]) — stated as a guard because this body walks find, and find("") is 0 forever. No traps.
str.replacen("a,b,c", ",", ";", 1) == "a;b,c"
str.replacen("a,b,c", ",", ";", 9) == "a;b;c"
str.replacen("a,b,c", ",", ";", 0) == "a,b,c"
str.replacen("a,b", "", "-", 2) == "a,b"
fn · Source line 721
pub fn lower(s: str) -> str
s with every code point lowercased, freshly allocated in the ambient region. Total: no error row, no traps beyond allocation.
The mapping is the implementation's, and it is worth stating plainly: the sprint contract planned ASCII-only case mapping here, but every pinned implementation performs simple Unicode case mapping ("ÉA" lowercases to "éa"). std delegates rather than reimplement, because an in-library mapping would need the case tables nothing carries in wolf source yet — so this function's contract is "the implementation's simple case mapping", and which mapping std should REQUIRE is the filed unicode-tables decision (F-0018). Locale is never a parameter, in core, ever.
str.lower("WOLF") == "wolf"
str.lower("Wolf-Lang") == "wolf-lang"
str.lower("") == ""
fn · Source line 734
pub fn upper(s: str) -> str
s with every code point uppercased, freshly allocated in the ambient region. The mapping story is lower's, exactly. Total: no error row, no traps beyond allocation.
str.upper("wolf") == "WOLF"
str.upper("Wolf-Lang") == "WOLF-LANG"
str.upper("") == ""
fn · Source line 752
pub fn eq_ignore_case(a: str, b: str) -> bool
Whether a and b are equal ignoring case, by comparing their case-folded forms. Total: no error row, no traps beyond allocation.
The sprint contract names this "ASCII, named honestly". The honest name at this pin drops the ASCII: the folding is lower's, which every pinned implementation performs over all of Unicode. Callers get case-insensitive comparison as strong as the implementation's lower — never weaker, and never locale-sensitive.
str.eq_ignore_case("WOLF", "wolf") == true
str.eq_ignore_case("Wolf", "wolves") == false
str.eq_ignore_case("", "") == true
fn · Source line 775
pub fn repeat(s: str, n: int) -> str
s repeated n times, freshly allocated. n == 0 gives the empty string. A NEGATIVE n traps assert — the language's own fault, from the builtin, on all three lanes: a repeat count cannot be negative, and s71 RULED the KIND ([mem.str.repeat], wolf-lang#57) to be the caller contract violation it is rather than the bounds the runtime used to report. std does not guard it, because a trap is the right answer for a violation the caller could have checked (§2) and because a guard would hide the one place the implementations agree. Twice re-measured, twice changed: sc03 read "" from the interpreter, sc09 measured trap(bounds) on every lane, sc11 measures trap(assert) on every lane — which is exactly why the claim lives in tests/str/repeat_negative_trap.lu and not only in this sentence (F-0056, closed).
str.repeat("ab", 3) == "ababab"
str.repeat("ab", 1) == "ab"
str.repeat("ab", 0) == ""
fn · Source line 789
pub fn trim(s: str) -> str
s with leading and trailing whitespace removed — a slice of s, no copy. Whitespace is Unicode White_Space (the builtin's set, pinned code point by code point by tests/str/trim_whitespace_set.lu). Total: no error row, no traps.
str.trim(" wolf ") == "wolf"
str.trim("\n\twolf\r\n") == "wolf"
str.trim(" ") == ""
fn · Source line 809
pub fn trim_start(s: str) -> str
s with LEADING whitespace removed — a slice of s, no copy. Same whitespace set as trim, and the equality of the two sets is a test, not a hope (§9). Total: no error row, no traps.
This body was 95 lines until sc09: a White_Space table written as starts_with probes, because sc03 had no way to scan a string it did not already know the shape of. s37's builtin trim_start replaced the table with a delegation, and the whitespace-set test outlived it — what it pins now is the BUILTIN's set, which is what it was always really checking.
str.trim_start(" wolf ") == "wolf "
str.trim_start("wolf") == "wolf"
str.trim_start(" ") == ""
fn · Source line 821
pub fn trim_end(s: str) -> str
s with TRAILING whitespace removed — a slice of s, no copy. Same whitespace set as trim. Total: no error row, no traps.
str.trim_end(" wolf ") == " wolf"
str.trim_end("wolf") == "wolf"
str.trim_end(" ") == ""
fn · Source line 838
pub fn lines(s: str) -> List[str]
The lines of s, in order, each without its terminator. A trailing newline does NOT produce a final empty line, and the empty string has no lines at all. \r\n counts as one terminator and the \r is not part of the line. Allocates the list (to_-grade allocation, §1); the lines themselves are slices of s. Total: no error row, no traps beyond allocation.
var seen = 0
for line in str.lines("a\nb\n") { seen = seen + 1 }
seen = seen + 0
seen == 2
fn · Source line 854
pub fn words(s: str) -> List[str]
The whitespace-separated words of s, in order, dropping empty runs: any run of whitespace separates, leading and trailing whitespace produce no empty words, and a string of only whitespace has no words. Whitespace is trim's set. Allocates the list; the words are slices of s. Total: no error row, no traps beyond allocation.
var seen = 0
for word in str.words(" the wolf ") { seen = seen + 1 }
seen = seen + 0
seen == 2
fn · Source line 874
pub fn each_word(s: str, f: fn(str) -> ()) -> ()
Walks the whitespace-separated words of s in order and calls f once per word, building nothing: the walk is the compiler's own lazy for-head over the receiver's bytes ([mem.str.view], s84), so each word is a zero-copy slice of s and no list exists. words is this walk with a List[str] at the end; when the list itself is not wanted, this is the cheaper spelling. Same word rule as words: whitespace is trim's set, empty runs separate, no word is empty — a string of only whitespace calls f zero times.
The example is prose because a doc example can neither define nor import a fn value (F-0085/F-0086; the sc13 convention): with fn shout(w: str) -> () { print("{w}") } at top level, str.each_word(" the wolf ", shout) prints the then wolf. tests/str/each_word_walk.lu is the measured witness — including the native-lane disassembly proving the walk fuses in std's own module context (no __wolf_rt_str_split, the inline predicate).
fn · Source line 889
pub fn words_count(s: str) -> int
The number of whitespace-separated words in s — words without the list OR the callback: the same fused walk as each_word, folded to a count. This fold earns its own name because the callable tier cannot express it: a fn value captures nothing (F-0085/F-0086), so counting through each_word has nowhere to put the counter. Word rule as ever: whitespace is trim's set, no word is empty — a whitespace-only or empty string counts zero.
str.words_count(" the wolf runs ") == 3
fn · Source line 913
pub fn join(sep: str, parts: List[str]) -> str
parts concatenated with the separator sep between consecutive items — the separator is the RECEIVER, as the sprint contract has it, which is why sep comes first. No separator is added before the first or after the last part; an empty list joins to the empty string and a one-item list to that item. Allocates in the ambient region. Total: no error row, no traps beyond allocation.
join and split are inverses whenever no part contains sep: join(sep, split(s, sep)) == s for every s and every non-empty sep, which tests/str/split_join_round_trip.lu holds them to.
var parts = List[str]()
(mut parts).push("the")
(mut parts).push("wolf")
str.join(" ", parts) == "the wolf"
str.join("", parts) == "thewolf"
fn · Source line 950
pub fn char_count(s: str) -> int
The number of CODE POINTS in s — the count len deliberately does not give (§9: a function that counts code points says so in its name). O(bytes), and equal to len(s) exactly when s is ASCII.
Counted by the UTF-8 invariant rather than by decoding: a lead byte is anything outside 128..191, so the count is the number of non- continuation bytes and no arithmetic can overflow. Total: no error row, no traps.
The walk consumes the byte view where it stands (for b in s.bytes()) rather than binding it first. s77 made that the difference between a view and a copy: bytes() is the receiver's own pointer and length in a consuming position, and a let binding is what materializes it. The body sc09 wrote bound bs and paid a list for every string it counted.
str.char_count("wolf") == 4
str.char_count("héllo") == 5
str.char_count("é🐺") == 2
str.char_count("") == 0
fn · Source line 981
pub fn char_offsets(s: str) -> List[int]
The byte offset at which each code point of s STARTS, in order — the offset half of the blocked chars() (see the module header), and every offset in it is a boundary get will accept. len(s) is deliberately NOT included: this lists code points, and there is none at the end.
Allocates the OUTPUT list and nothing else. The offset is carried in a counter beside a for over the byte view rather than driving an index INTO it. That spelling was a lane decision when it was written — indexing a view was refused by wolfc's checked tier (F-0071, closed at the sc12 pin) — and it is kept now because it is the better body: one pass, one counter, no list. The body sc09 wrote bound bs first and copied every byte of s before reading one of them.
Total: no error row, no traps beyond the output list's allocation.
var last = 0 - 1
for at in str.char_offsets("héllo") { last = at }
last == 5
fn · Source line 1036
pub fn code_points(s: str) -> List[int]
The Unicode SCALAR VALUES of s's code points, in order, as ints. Born (sc09) as the interim face of the then-blocked to_list_chars; kept (sc25) as something better: std's own one-pass UTF-8 reading, independent of the builtin chars(), which is what lets tests/str/chars_builtin_agree.lu hold the two readings against each other element by element — the bytes.is_utf8 pattern one tier up. A caller that wants chars calls to_list_chars; a caller that wants the numbers (a table index, a range check against a numeric spec) takes these and crosses back through unicode.from_code, the one validating door. std.unicode's classifiers take char as of the sc25 retype, so this list no longer feeds them directly — that composition moved to chars().
Total over every str: a str is valid UTF-8 by construction (D24), so the decode below has no error path and needs no validation — the version of it that DOES validate is std.bytes.is_utf8, over bytes nobody promised anything about. Allocates the OUTPUT list and nothing else.
The decoder is a one-pass state machine now, and that is the shape the byte view asks for. sc09 wrote it as a random-access walk — bind the list, read bs[i + 1], bs[i + 2], bs[i + 3], advance i by the width — which needed a materialized copy to index into. s77 makes iteration the free position, so the lead byte now sets a PENDING count and each continuation folds six bits into the accumulator. The two forms agree byte for byte; this one reads s's own storage and never builds a list to read it from, and it is shorter — which is why it stayed after F-0071 (the checked tier's refusal of an indexed view) closed at the sc12 pin.
The continuation count is trusted rather than checked, and that is the UTF-8 invariant rather than an oversight: a lead byte in a valid str is followed by exactly as many continuations as it announces. std.bytes.is_utf8 is where that assumption is checked, because there the bytes are a caller's and not the language's.
var sum = 0
for c in str.code_points("aé") { sum = sum + c }
sum = sum + 0
sum == 330
fn · Source line 1091
pub fn to_list_chars(s: str) -> List[char]
The code points of s as CHARS, in order — the sc03 contract's to_list_chars, code at last (sc24): a delegation to the language's s.chars() ([mem.str.chars], s120/s121), which yields the Unicode scalar values List[char]-typed under D58's ruling — a scalar value, ordered by scalar value, NOT an integer. code_points above is this function in the pre-D58 int currency and the two agree element for element (unicode.code(c) is the bridge; the agreement is a test, tests/str/chars_builtin_agree.lu, held as two independent UTF-8 readings — the builtin's and std's own decoder's). Total over every str: a str is valid UTF-8 by construction (D24), so no element can fall outside char's domain — which is exactly why the clause can promise the type. Allocates the output list. No error row, no traps beyond allocation.
LANES, stated honestly (the sc24 rule: a zero-lane surface is zero evidence, and a by-lane surface says so): every executing lane runs this as of the sc25 pins — both wolf rungs since s121, and lupin since 0.1.15 (is26, the scalar release), where sc24's tests and example were honestly unsupported for one sprint. The doc-example waiver that named that debt died with it, on schedule.
let cs = str.to_list_chars("aé🐺")
cs.len == 3
let e = str.to_list_chars("")
e.len == 0
fn · Source line 1115
pub fn is_ascii(s: str) -> bool
Whether every code point in s is ASCII (below U+0080) — the cheap question a caller asks before treating byte offsets as character positions, and the one classification that needs no tables at all. The empty string is ASCII. Total: no error row, no traps.
is_ascii(s) is exactly char_count(s) == len(s), and it is a function rather than that expression because the equality is a fact about UTF-8 the caller should not have to know.
It is also the cheapest function in this module to get wrong the expensive way: until sc12 it copied every byte of s into a list and then returned false at the first one above 127. It walks the view now and stops there — a return out of a for over s.bytes() runs on all three lanes.
str.is_ascii("wolf-lang") == true
str.is_ascii("héllo") == false
str.is_ascii("") == true
fn · Source line 1137
pub fn to_strbuf(s: str) -> strbuf.StrBuf
s copied into a fresh std.strbuf.StrBuf — the allocating conversion into the builder (to_, §1: it allocates). strbuf.to_str is the direction back, and since sc75 it copies too, once (the builder holds bytes, wolf-std#108). O(len(s)). Total: no error row, no traps beyond allocation.
No fenced example: asserting about the result needs std.strbuf, and the extractor imports exactly the documented module (§4's one-module note), so the worked example lives in tests/str/to_strbuf_round_trip.lu instead. In prose: after let b = str.to_strbuf("wolf"), strbuf.len(b) is 4 and strbuf.to_str(b) is "wolf" — and appending to b leaves s untouched, because str is immutable and this is a copy.