Skip to content

String search and transformation builtins #198

Description

@aallan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    codegenCode generation backendenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions