summaryrefslogtreecommitdiff
path: root/libstd/strjoin.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-01-15 19:00:03 -0500
committerOri Bernstein <ori@eigenstate.org>2014-01-15 19:00:03 -0500
commite1dd87b2721b7b42e252d83330798e73daf48a27 (patch)
tree4e9df0f37f0c2eee5e3c3cc5e7f858d143baf2af /libstd/strjoin.myr
parent0f342c47db402a0b4ba021dab79414941180c1f0 (diff)
downloadmc-e1dd87b2721b7b42e252d83330798e73daf48a27.tar.gz
Fix writing constant struct literals
We had alignment and padding issues. Fixed.
Diffstat (limited to 'libstd/strjoin.myr')
-rw-r--r--libstd/strjoin.myr14
1 files changed, 11 insertions, 3 deletions
diff --git a/libstd/strjoin.myr b/libstd/strjoin.myr
index e7ad4e6..518a4dc 100644
--- a/libstd/strjoin.myr
+++ b/libstd/strjoin.myr
@@ -4,14 +4,14 @@ use "slcp.use"
pkg std =
const strcat : (a : byte[:], b : byte[:] -> byte[:])
- const strjoin : (strings : byte[:][:] -> byte[:])
+ const strjoin : (strings : byte[:][:], delim : byte[:] -> byte[:])
;;
const strcat = {a, b
- -> strjoin([a, b][:])
+ -> strjoin([a, b][:], "")
}
-const strjoin = {strings
+const strjoin = {strings, delim
var len, off
var i
var s
@@ -20,12 +20,20 @@ const strjoin = {strings
for i = 0; i < strings.len; i++
len += strings[i].len
;;
+ if strings.len > 0
+ len += (strings.len - 1)*delim.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
+ /* we don't want to terminate the last string with delim */
+ if i != strings.len - 1
+ slcp(s[off:off + delim.len], delim)
+ off += delim.len
+ ;;
;;
-> s
}