Rope data structure implementation in Hare.
1use text;
2use strings;
3
4// TODO: docs
5export type Leaf = struct {
6 buf: []rune,
7 length: size,
8};
9
10// TODO: docs
11fn leaf_close(leaf: *Leaf) void = free(leaf.buf);
12
13// TODO: docs
14fn leaf_new() Leaf = Leaf {
15 buf = strings::torunes(""),
16 length = 0: size,
17};
18
19// TODO: docs
20fn leaf_fromstr(string: str) Leaf = Leaf {
21 buf = strings::torunes(string),
22 length = len(string),
23};
24
25// TODO: docs
26fn leaf_at(leaf: *const Leaf, idx: size) (rune | indexerror) = if (idx > leaf.length) {
27 yield indexerror;
28} else {
29 yield leaf.buf[idx];
30};