ref: afc7520151f5ea1c30be31e9eb85e58dd863d632
parent: d752a67b5b88c1e6ae9e632a960dc9ef23827d44
author: Ori Bernstein <[email protected]>
date: Fri Dec 27 12:36:43 EST 2013
Added 'strjoin' to libstd
--- a/libstd/Makefile
+++ b/libstd/Makefile
@@ -26,6 +26,7 @@
slpush.myr \
slurp.myr \
strfind.myr \
+ strjoin.myr \
strsplit.myr \
strstrip.myr \
strcmp.myr \
--- a/libstd/optparse.myr
+++ b/libstd/optparse.myr
@@ -26,6 +26,7 @@
const optinit : (optstr: byte[:], optargs : byte[:][:] -> optctx#)
const optnext : (ctx : optctx# -> [char, byte[:]])
const optdone : (ctx : optctx# -> bool)
+ const optfin : (ctx : optctx# -> byte[:][:])
;;
const optinit = {optstr, optargs
@@ -44,6 +45,14 @@
next(ctx)
-> ctx
+}
+
+const optfin = {ctx
+ var a
+
+ a = ctx.args
+ free(ctx)
+ -> a
}
const optnext = {ctx
--- /dev/null
+++ b/libstd/strjoin.myr
@@ -1,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
+}
+
+
--- a/libstd/utf.myr
+++ b/libstd/utf.myr
@@ -11,11 +11,6 @@
const encode : (buf : byte[:], chr : char -> size)
const decode : (buf : byte[:] -> char)
const striter : (str : byte[:] -> [char, byte[:]])
-
- const strjoin : (lst : byte[:][:], delim:byte[:] -> byte[:])
- const strsep : (str : byte[:], delim:byte[:] -> byte[:][:])
- const strbjoin : (lst : byte[:][:], delim:byte[:] -> byte[:])
- const strbsep : (str : byte[:], delim:byte[:] -> byte[:][:])
;;
const charlen = {c
--- /dev/null
+++ b/test/data/strjoin-expected
@@ -1,0 +1,2 @@
+foo;bar
+xyzw
--- /dev/null
+++ b/test/strjoin.myr
@@ -1,0 +1,12 @@
+use std
+
+const main = {
+ const strings = [
+ "x",
+ "y",
+ "z",
+ "w"
+ ]
+ std.put("%s\n", std.strcat("foo;", "bar"))
+ std.put("%s\n", std.strjoin(strings[:]))
+}
--- a/test/tests
+++ b/test/tests
@@ -110,6 +110,7 @@
B strstrip C
B strsplit C
B strfind C
+B strjoin C
# B local-labels E 10 ## BUGGERED
F declmismatch
F infermismatch