~sircmpwn/hare

8680b52afbc819dc4076e6e49f85256ca93b5b10 — Sebastian 2 months ago f35e04c
strings: take direction into account in iterstr

So it returns a slice from the current position to the beginning of the
string for reverse iterators

Signed-off-by: Sebastian <sebastian@sebsite.pw>
1 files changed, 7 insertions(+), 2 deletions(-)

M strings/iter.ha
M strings/iter.ha => strings/iter.ha +7 -2
@@ 61,9 61,14 @@ fn move(forward: bool, iter: *iterator) (rune | void) = {
	};
};

// Return a substring from the next rune to the end of the string.
// Return a substring from the next rune to the end of the string if initialized
// with [[iter]], or the beginning of the string if initialized with [[riter]].
export fn iterstr(iter: *iterator) str = {
	return fromutf8_unsafe(iter.dec.src[iter.dec.offs..])!;
	if (iter.reverse) {
		return fromutf8_unsafe(iter.dec.src[..iter.dec.offs]);
	} else {
		return fromutf8_unsafe(iter.dec.src[iter.dec.offs..]);
	};
};

// Return a substring from the position of the first iterator to the position of