veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

text

lib/text.vk

lib/text.vk Pure-Veko string inspection, replacement, splitting, ASCII predicates, slugification, and UTF-8 helpers. Zero capabilities required.

signature
starts-with? = fn [s str, pfx str] bool

Returns true if s starts with pfx.

Executable Example
veko
use [text]
if (not (text/starts-with? 'veko-1.0' 'veko')) or (text/starts-with? 'hi' 'hello') [ err 'starts-with' ] else [ .ok ]
signature
ends-with? = fn [s str, sfx str] bool

Returns true if s ends with sfx.

signature
contains? = fn [s str, needle str] bool

Returns true if s contains needle.

signature
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.

signature
last-index-of = fn [s str, needle str] i64

Finds the last byte index of needle in s, or -1 if absent.

signature
replace = fn [s str, old_s str, new_s str] str

Replaces the first occurrence of old_s in s with new_s.

signature
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.

Executable Example
veko
use [text]
if (text/replace-all 'a-b-c' '-' '_') != 'a_b_c' [ err 'replace-all' ] else [ .ok ]
signature
repeat = fn [s str, count i64] str

Repeats s count times ('' if count <= 0).

signature
trim-prefix = fn [s str, pfx str] str

Strips pfx from the start of s if present.

signature
trim-suffix = fn [s str, sfx str] str

Strips sfx from the end of s if present.

signature
lines = fn [s str] block[str]

Splits s into lines, handling both \n and \r\n.

Executable Example
veko
use [text]
ls = text/lines 'a\r\nb\nc'
if (len ls) != 3 or ls[1] != 'b' [ err 'text/lines' ] else [ .ok ]
signature
ascii-space? = fn [b i64] bool

Returns true if ASCII byte b is whitespace ( , \t, \r, \n).

signature
ascii-alpha? = fn [b i64] bool

Returns true if ASCII byte b is an ASCII letter (A..Z or a..z).

signature
ascii-digit? = fn [b i64] bool

Returns true if ASCII byte b is an ASCII decimal digit (0..9).

signature
ascii-alnum? = fn [b i64] bool

Returns true if ASCII byte b is alphanumeric (A..Z, a..z, 0..9).

signature
ascii-hex? = fn [b i64] bool

Returns true if ASCII byte b is a hexadecimal digit (0..9, a..f, A..F).

signature
words = fn [s str] block[str]

Splits s on contiguous ASCII whitespace into non-empty words.

Executable Example
veko
use [text]
ws = text/words '  veko   is\tfast\n '
if (len ws) != 3 or ws[2] != 'fast' [ err 'text/words' ] else [ .ok ]
signature
slugify = fn [s str] str

Converts s into a lowercase URL-safe ASCII slug ('Hello, Veko 1.0!' -> 'hello-veko-1-0').

Executable Example
veko
use [text]
if (text/slugify 'Hello, Veko 1.0!') != 'hello-veko-1-0' [ err 'slugify' ] else [ .ok ]
signature
utf8-len = fn [s str] i64

Counts Unicode code points in a UTF-8 string s.

Executable Example
veko
use [text]
if (text/utf8-len 'Veko') != 4 [ err 'utf8-len' ] else [ .ok ]
signature
utf8-codepoints = fn [s str] block[i64]

Decodes a UTF-8 string into a block[i64] of Unicode scalar code points.

signature
utf8-from-codepoints = fn [cps block[i64]] str

Encodes a block[i64] of Unicode code points into a UTF-8 str.