summaryrefslogtreecommitdiff
path: root/libstd/strjoin.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2013-12-27 17:36:43 -0500
committerOri Bernstein <ori@eigenstate.org>2013-12-27 17:36:43 -0500
commitafc7520151f5ea1c30be31e9eb85e58dd863d632 (patch)
treee93cc9cfc3320c2e156e5b0535f34017428f2c22 /libstd/strjoin.myr
parentd752a67b5b88c1e6ae9e632a960dc9ef23827d44 (diff)
downloadmc-afc7520151f5ea1c30be31e9eb85e58dd863d632.tar.gz
Added 'strjoin' to libstd
Diffstat (limited to 'libstd/strjoin.myr')
-rw-r--r--libstd/strjoin.myr33
1 files changed, 33 insertions, 0 deletions
diff --git a/libstd/strjoin.myr b/libstd/strjoin.myr
new file mode 100644
index 0000000..e7ad4e6
--- /dev/null
+++ b/libstd/strjoin.myr
@@ -0,0 +1,33 @@
+use "alloc.use"
+use "die.use"
+use "slcp.use"
+
+pkg std =
+ const strcat : (a : byte[:], b : byte[:] -> byte[:])
+ const strjoin : (strings : byte[:][:] -> byte[:])
+;;
+
+const strcat = {a, b
+ -> strjoin([a, b][:])
+}
+
+const strjoin = {strings
+ var len, off
+ var i
+ var s
+
+ len = 0
+ for i = 0; i < strings.len; i++
+ len += strings[i].len
+ ;;
+
+ s = slalloc(len)
+ off = 0
+ for i = 0; i < strings.len; i++
+ slcp(s[off:off + strings[i].len], strings[i])
+ off += strings[i].len
+ ;;
+ -> s
+}
+
+