Functions for working with text (UTF-8 strings) and character values. Read the value of a variable and put a reference to it on the stack
pub fn len(both: text) -> integer
Number of bytes in the text. Use for bounds checks and iteration limits.
pub fn size(both: text) -> integer
Number of Unicode code points (characters) in the text.
pub fn len(both: character) -> integer
Byte length of the character's UTF-8 encoding (1–4).
Splits self on every occurrence of separator and returns the parts as a vector. Use to parse CSV lines or space-separated tokens.
pub fn split(self: text, separator: character) -> vector < text >
pub fn split_text(self: text, separator: text) -> vector < text >
pub fn join(self: vector<text>, jn_sep: text) -> text
pub fn starts_with_at(self: text, pos: integer, prefix: text) -> boolean
Functions for searching, transforming, and classifying text and character values. Character classification functions return true only if every character in the text satisfies the condition. The single-character variants test one code point. (`starts_with` / `ends_with` moved to `02_files.loft` so the path helpers there can call them; both still available as `text.starts_with` / `text.ends_with`.) Returns true if self contains `prefix` starting at byte position `pos`. Sugar over `self[pos..pos + prefix.len()] == prefix` for the common "is this token at this offset?" pattern in scanners / parsers. Returns false (not an error) when pos + prefix.len() exceeds self.len() — same shape as `starts_with` for the "prefix too long for input" case.
Added in @PLAN37 phase 10.5 — closes a stdlib gap surfaced by scan.loft's @PLAN matcher doing `line[i+1] == 'P' && line[i+2] == 'L' && line[i+3] == 'A' && line[i+4] == 'N'` per-char instead of `line.starts_with_at(i, "PLAN")`.
pub fn trim(both: text) -> text[both]
(Path helpers `dir` / `basename` / `join` / `resolve` moved to `02_files.loft` § Path helpers, so they're available before `03_text.loft` loads — same call shape, same `pub fn` signatures.) Removes leading and trailing whitespace. Use when processing user input or file content.
pub fn trim_start(self: text) -> text[self]
Removes leading whitespace only.
pub fn trim_end(self: text) -> text[self]
Removes trailing whitespace only.
pub fn find(self: text, value: text) -> integer
Returns the byte index of the first occurrence of value, or null if not found. Use to locate substrings before slicing.
pub fn rfind(self: text, value: text) -> integer
Returns the byte index of the last occurrence of value, or null if not found. Use to find file extensions or the last path separator.
pub fn contains(self: text, value: text) -> boolean
Returns true if value appears anywhere in self. Simpler than find when you only need a yes/no answer.
pub fn replace(self: text, value: text, with: text) -> text
Returns a copy of self with every occurrence of value replaced by with.
pub fn to_lowercase(self: text) -> text
Returns a lowercase copy. Use for case-insensitive comparisons.
pub fn to_uppercase(self: text) -> text
Returns an uppercase copy.
pub fn is_lowercase(self: text) -> boolean
True if all characters are lowercase letters.
pub fn is_lowercase(self: character) -> boolean
True if the character is a lowercase letter.
pub fn is_uppercase(self: text) -> boolean
True if all characters are uppercase letters.
pub fn is_uppercase(self: character) -> boolean
True if the character is an uppercase letter.
pub fn is_numeric(self: text) -> boolean
True if all characters are numeric digits (Unicode numeric, not just ASCII 0–9).
pub fn is_numeric(self: character) -> boolean
True if the character is a numeric digit.
pub fn is_alphanumeric(self: text) -> boolean
True if all characters are letters or digits. Use to validate identifiers or tokens.
pub fn is_alphanumeric(self: character) -> boolean
True if the character is a letter or digit.
pub fn is_alphabetic(self: text) -> boolean
True if all characters are alphabetic.
pub fn is_alphabetic(self: character) -> boolean
True if the character is alphabetic.
pub fn is_whitespace(self: text) -> boolean
True if all characters are whitespace. Use to detect blank lines.
pub fn is_whitespace(self: character) -> boolean
True if the character is whitespace.
pub fn is_control(self: text) -> boolean
True if all characters are control characters.
pub fn is_control(self: character) -> boolean
True if the character is a control character.
pub fn join(parts: vector < text >, sep: text) -> text
Joins parts with sep between each consecutive pair. Returns "" for an empty vector. Use to build comma-separated lists, path segments, or any delimited output.