text
lib/text.vklib/text.vk Pure-Veko string inspection, replacement, splitting, ASCII predicates, slugification, and UTF-8 helpers. Zero capabilities required.
starts-with? = fn [s str, pfx str] bool
Returns true if s starts with pfx.
use [text]
if (not (text/starts-with? 'veko-1.0' 'veko')) or (text/starts-with? 'hi' 'hello') [ err 'starts-with' ] else [ .ok ]
index-of = fn [s str, needle str, start i64] i64
Finds the first byte index of needle in s starting at start, or -1 if absent.
last-index-of = fn [s str, needle str] i64
Finds the last byte index of needle in s, or -1 if absent.
replace = fn [s str, old_s str, new_s str] str
Replaces the first occurrence of old_s in s with new_s.
replace-all = fn [s str, old_s str, new_s str] str
Replaces every non-overlapping occurrence of old_s in s with new_s.
use [text]
if (text/replace-all 'a-b-c' '-' '_') != 'a_b_c' [ err 'replace-all' ] else [ .ok ]
lines = fn [s str] block[str]
Splits s into lines, handling both \n and \r\n.
use [text]
ls = text/lines 'a\r\nb\nc'
if (len ls) != 3 or ls[1] != 'b' [ err 'text/lines' ] else [ .ok ]
ascii-space? = fn [b i64] bool
Returns true if ASCII byte b is whitespace ( , \t, \r, \n).
ascii-alpha? = fn [b i64] bool
Returns true if ASCII byte b is an ASCII letter (A..Z or a..z).
ascii-digit? = fn [b i64] bool
Returns true if ASCII byte b is an ASCII decimal digit (0..9).
ascii-alnum? = fn [b i64] bool
Returns true if ASCII byte b is alphanumeric (A..Z, a..z, 0..9).
ascii-hex? = fn [b i64] bool
Returns true if ASCII byte b is a hexadecimal digit (0..9, a..f, A..F).
words = fn [s str] block[str]
Splits s on contiguous ASCII whitespace into non-empty words.
use [text]
ws = text/words ' veko is\tfast\n '
if (len ws) != 3 or ws[2] != 'fast' [ err 'text/words' ] else [ .ok ]
slugify = fn [s str] str
Converts s into a lowercase URL-safe ASCII slug ('Hello, Veko 1.0!' -> 'hello-veko-1-0').
use [text]
if (text/slugify 'Hello, Veko 1.0!') != 'hello-veko-1-0' [ err 'slugify' ] else [ .ok ]
utf8-len = fn [s str] i64
Counts Unicode code points in a UTF-8 string s.
use [text]
if (text/utf8-len 'Veko') != 4 [ err 'utf8-len' ] else [ .ok ]
utf8-codepoints = fn [s str] block[i64]
Decodes a UTF-8 string into a block[i64] of Unicode scalar code points.
utf8-from-codepoints = fn [cps block[i64]] str
Encodes a block[i64] of Unicode code points into a UTF-8 str.