Lynxer

Documentation

text

String helpers built on the core string builtins.

Backend: Lynxer helpers backed by the Rust text.so Unicode operations. Import: import("text") → global.text.*

The interpreter's strings hold UTF-8, and length, indexing and slicing here count code points, so a character is one Unicode scalar value. Unicode case conversion uses the per-character Unicode mappings and can expand one character, such as ß to SS. Predicates use Unicode alphabetic/numeric properties. Combining marks are separate scalars and do not count as alphabetic on their own.

Search and replace

FunctionSignatureNotes
contains(str value, str needle) -> boolSubstring test (true for an empty needle)
startsWith / endsWith(str value, str affix) -> boolPrefix / suffix test
indexOf(str value, str needle) -> intFirst index, or -1; 0 for an empty needle
count(str value, str needle) -> intNon-overlapping occurrences
replace(str value, str old, str new) -> strReplaces every occurrence
replaceFirst(str value, str old, str new) -> strReplaces the first occurrence
remove(str value, str target) -> strRemoves every occurrence

contains here is a substring test, unlike the core contains builtin, which only tests list/tuple membership.

Case

FunctionSignatureNotes
upper / lower(str value) -> strUnicode case conversion
upperAscii / lowerAscii(str value) -> strASCII-only conversion, retained for compatibility
capitalize(str value) -> strUpper-case the first character, lower-case the rest
title(str value) -> strCapitalise the first letter of each word
swapCase(str value) -> strSwap upper/lower per character

Whitespace and repetition

FunctionSignatureNotes
trim(str value) -> strRemoves leading and trailing whitespace
trimLeft / trimRight(str value) -> strRemoves leading / trailing whitespace
repeat(str value, int count) -> strRepeats count times
spaces(int count) -> strcount space characters
expandTabs(str value, int tabSize) -> strExpand tabs to tabSize-wide stops
wordWrap(str value, int width) -> strGreedy wrap on spaces
indent(str value, str prefix) -> strPrefix every line

Predicates

FunctionSignatureNotes
isEmpty(str value) -> boolZero length
isBlank(str value) -> boolOnly whitespace
isAlpha(str value) -> boolEvery character is Unicode alphabetic; false for ""
isNumeric / isDigit(str value) -> boolEvery character has a Unicode numeric property; false for ""
isAlphaNumeric(str value) -> boolEvery character is Unicode alphabetic or numeric; false for ""
isAlphaAscii(str value) -> boolEvery character is an ASCII letter
isNumericAscii / isDigitAscii(str value) -> boolEvery character is an ASCII digit
isAlphaNumericAscii(str value) -> boolEvery character is ASCII alphanumeric

Padding and slicing

FunctionSignatureNotes
padLeft / padRight / center(str value, int width, str fill) -> strPad to width
zfill(str value, int width) -> strZero-pad, keeping a leading sign
substring(str value, int start, int end) -> strHalf-open slice (builtin forwarder)
charAt(str value, int index) -> strOne-character string (builtin forwarder)
reverse(str value) -> strReverse the characters

Splitting and joining

FunctionSignatureNotes
split(str value, str separator) -> listSplit into a list
splitLines(str value) -> listSplit on newlines (\r\n aware)
splitFirst(str value, str separator) -> listTwo-element [before, after]
join(list parts, str separator) -> strJoin a list

Example

global setup(){ import("text"); }

global main(){
    println(global.text.reverse("abc"));        // cba
    println(global.text.contains("hello", "ell")); // true
    println(global.text.count("banana", "na")); // 2
    println(global.text.indexOf("banana", "na")); // 2
    println(global.text.zfill("42", 5));        // 00042
    println(global.text.splitFirst("a=b", "=")); // [a, b]
}

See also