Add built-in string operations for searching and transforming strings. Currently Vera has 13 string builtins (length, concat, slice, char_code, strip, parse_nat, parse_float64, to_string, and the v0.0.64 type-to-string family), but lacks common search and transformation operations.
Proposed functions
Search
string_contains(@String, @String -> @Bool) — substring search
starts_with(@String, @String -> @Bool) — prefix check
ends_with(@String, @String -> @Bool) — suffix check
index_of(@String, @String -> @Option<Nat>) — first occurrence index (None if not found)
Transformation
to_upper(@String -> @String) — ASCII uppercase
to_lower(@String -> @String) — ASCII lowercase
replace(@String, @String, @String -> @String) — replace all occurrences
split(@String, @String -> @Array<String>) — split by delimiter
join(@Array<String>, @String -> @String) — join with separator
Implementation notes
All are pure functions. Search operations are simple byte-level loops in WAT. Transformation operations allocate via the bump allocator. split returns an Array<String> (compound array support landed in v0.0.61). join is the inverse.
The pattern for adding builtins is established: register in environment.py, implement in wasm/calls.py, add inference in wasm/inference.py, add to known set in codegen/modules.py.
Dependencies
Add built-in string operations for searching and transforming strings. Currently Vera has 13 string builtins (length, concat, slice, char_code, strip, parse_nat, parse_float64, to_string, and the v0.0.64 type-to-string family), but lacks common search and transformation operations.
Proposed functions
Search
string_contains(@String, @String -> @Bool)— substring searchstarts_with(@String, @String -> @Bool)— prefix checkends_with(@String, @String -> @Bool)— suffix checkindex_of(@String, @String -> @Option<Nat>)— first occurrence index (None if not found)Transformation
to_upper(@String -> @String)— ASCII uppercaseto_lower(@String -> @String)— ASCII lowercasereplace(@String, @String, @String -> @String)— replace all occurrencessplit(@String, @String -> @Array<String>)— split by delimiterjoin(@Array<String>, @String -> @String)— join with separatorImplementation notes
All are pure functions. Search operations are simple byte-level loops in WAT. Transformation operations allocate via the bump allocator.
splitreturns anArray<String>(compound array support landed in v0.0.61).joinis the inverse.The pattern for adding builtins is established: register in
environment.py, implement inwasm/calls.py, add inference inwasm/inference.py, add to known set incodegen/modules.py.Dependencies
splitbenefits from compound array codegen (Arrays of compound types in codegen #132, done)