~sircmpwn/hare-dev

hare: strings: simplify iter direction logic v1 PROPOSED

Bor Grošelj Simić: 1
 strings: simplify iter direction logic

 1 files changed, 6 insertions(+), 28 deletions(-)
#933552 alpine.yml success
#933553 freebsd.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/hare-dev/patches/38681/mbox | git am -3
Learn more about email & git

[PATCH hare] strings: simplify iter direction logic Export this patch

Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>
---
 strings/iter.ha | 34 ++++++----------------------------
 1 file changed, 6 insertions(+), 28 deletions(-)

diff --git a/strings/iter.ha b/strings/iter.ha
index 25bdd6ad..e0b29014 100644
--- a/strings/iter.ha
+++ b/strings/iter.ha
@@ -47,38 +47,16 @@ export fn riter(src: str) iterator = {
// reordering, editing, or omitting any of the runes without careful discretion
// may cause linguistic errors to arise. To avoid this, you may need to use a
// third-party Unicode module instead.
export fn next(iter: *iterator) (rune | void) = {
	if (iter.reverse) {
		return next_backward(iter);
	 } else {
		return next_forward(iter);
	 };
};

fn next_forward(iter: *iterator) (rune | void) = {
	return match (utf8::next(&iter.dec)) {
	case void => void;
	case (utf8::more | utf8::invalid) =>
		abort("Invalid UTF-8 string (this should not happen)");
	case let r: rune =>
		yield r;
	};
};
export fn next(iter: *iterator) (rune | void) = move(!iter.reverse, iter);

// Get the previous rune from an iterator, or void when at the start of the
// string.
export fn prev(iter: *iterator) (rune | void) = {
	if (iter.reverse) {
		return next_forward(iter);
	 } else {
		return next_backward(iter);
	 };
};
export fn prev(iter: *iterator) (rune | void) = move(iter.reverse, iter);

fn next_backward(iter: *iterator) (rune | void) = {
	return match (utf8::prev(&iter.dec)) {
	case void =>
		yield void;
fn move(forward: bool, iter: *iterator) (rune | void) = {
	let fun = if (forward) &utf8::next else &utf8::prev;
	return match (fun(&iter.dec)) {
	case void => void;
	case (utf8::more | utf8::invalid) =>
		abort("Invalid UTF-8 string (this should not happen)");
	case let r: rune =>
-- 
2.36.4
hare/patches: SUCCESS in 1m42s

[strings: simplify iter direction logic][0] from [Bor Grošelj Simić][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/38681
[1]: mailto:bgs@turminal.net

✓ #933552 SUCCESS hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/933552
✓ #933553 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/933553