summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-06-05 21:39:21 -0700
committerKaz Kylheku <kaz@kylheku.com>2020-06-05 21:39:21 -0700
commitd453e38a773a618ead6772f34c9beff73b0c2d1d (patch)
tree0d5b958f3f8bf6769e2601b71347ae345b6380b8 /lib.c
parent78737373eb4142158181ad4305ab21936b487833 (diff)
downloadtxr-d453e38a773a618ead6772f34c9beff73b0c2d1d.tar.gz
txr-d453e38a773a618ead6772f34c9beff73b0c2d1d.tar.bz2
txr-d453e38a773a618ead6772f34c9beff73b0c2d1d.zip
seq_iter_rewind: support iterables.
This fixes cases like (isec 0..10 5..15). * lib.c (seq_iter_rewind): Handle the rewinding of non-sequence iterators (ranges, characters, numbers).
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index 61e89907..486ceee8 100644
--- a/lib.c
+++ b/lib.c
@@ -559,6 +559,37 @@ void seq_iter_rewind(seq_iter_t *it)
it->ui.iter = hash_begin(it->inf.obj);
break;
default:
+ switch (it->inf.type) {
+ case RNG:
+ {
+ val rf = from(it->inf.obj);
+
+ switch (type(rf)) {
+ case NUM:
+ it->ui.cn = c_num(rf);
+ break;
+ case CHR:
+ it->ui.cn = c_chr(rf);
+ break;
+ case BGNUM:
+ it->ui.vn = rf;
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ case CHR:
+ it->ui.cn = c_chr(it->inf.obj);
+ break;
+ case NUM:
+ case BGNUM:
+ case FLNUM:
+ it->ui.vn = it->inf.obj;
+ break;
+ default:
+ break;
+ }
break;
}
}