1use <prelude.kav>
2use <mem.kav> as mem
3
4extern fn kavstrlen(s: cstr) -> int
5
6/% Return the length of a string %/
7pub fn len(s: cstr) -> int {
8 kavstrlen(s)
9}
10
11/% Return the character at i in s %/
12pub fn at(s: cstr, i: int) -> int {
13 if i < 0 then -1
14 else if i >= len(s) then -1
15 else mem::load8(mem::add(s as ptr, i)) as int
16}
17
18fn eqat(a: cstr, b: cstr, i: int) -> bool {
19 val ca = mem::load8(mem::add(a as ptr, i))
20 val cb = mem::load8(mem::add(b as ptr, i))
21 if ca != cb then false
22 else if ca == 0 then true
23 else eqat(a, b, i + 1)
24}
25
26/% Check if two strings are equal %/
27pub fn eq(a: cstr, b: cstr) -> bool {
28 eqat(a, b, 0)
29}