hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 8680b52afbc819dc4076e6e49f85256ca93b5b10
parent f35e04cdd4a90544b7842a84c24c0fba3df7dd46
Author: Sebastian <sebastian@sebsite.pw>
Date:   Mon, 27 Nov 2023 01:18:09 -0500

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>

Diffstat:
Mstrings/iter.ha | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/strings/iter.ha b/strings/iter.ha @@ -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