shithub: mc

Download patch

ref: 4abdb2acb85699bd1a43118b7189c5a504d65a19
parent: b7912fb2d55e18e14ad123338f8dfc8e1329c6b4
author: Ori Bernstein <[email protected]>
date: Thu Jan 9 13:01:19 EST 2014

Add 'slinsert' function.

--- a/libstd/Makefile
+++ b/libstd/Makefile
@@ -27,6 +27,7 @@
     sldup.myr \
     sleq.myr \
     slfill.myr \
+    slinsert.myr \
     sljoin.myr \
     slpush.myr \
     slurp.myr \
--- /dev/null
+++ b/libstd/slinsert.myr
@@ -1,0 +1,20 @@
+use "types.use"
+use "alloc.use"
+use "fmt.use"
+
+pkg std =
+	generic slinsert	: (sl : @a[:], idx : size, elt : @a	-> @a[:])
+;;
+
+generic slinsert = {sl, idx, elt
+	var i
+	var len
+
+	len = sl.len
+	sl = slgrow(sl, sl.len + 1)
+	for i = 0; i < (len - idx); i++
+		sl[sl.len - i] = sl[len - i]
+	;;
+	sl[idx] = elt
+	-> sl
+}