mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
Fix crashes in String.join/join-with-char with empty array.
This commit is contained in:
parent
78181991f7
commit
aa71647d02
@ -114,7 +114,7 @@
|
||||
(defn join [sep strings]
|
||||
(let-do [j 0
|
||||
lstrings (Array.length strings)
|
||||
num-seps (- lstrings 1)
|
||||
num-seps (max 0 (- lstrings 1))
|
||||
sep-length (String.length &sep)
|
||||
seps-size (* num-seps sep-length)
|
||||
result (String.allocate (+ seps-size (sum-length strings)) \ )]
|
||||
@ -134,7 +134,7 @@
|
||||
;; (= (join-with-char \ ["Hello" "world"]) (join " " ["Hello" "world"]))
|
||||
(let-do [j 0
|
||||
lstrings (Array.length strings)
|
||||
sep-length (- lstrings 1)
|
||||
sep-length (max 0 (- lstrings 1))
|
||||
result (String.allocate (+ sep-length (sum-length strings)) \ )]
|
||||
(for [i 0 lstrings]
|
||||
(let-do [str (Array.nth strings i)
|
||||
|
@ -210,6 +210,10 @@
|
||||
"hello aaaa there aaaa world"
|
||||
&(join @" aaaa " &[@"hello" @"there" @"world"])
|
||||
"join works correctly III")
|
||||
(assert-equal test
|
||||
""
|
||||
&(join @" aaaa " &[])
|
||||
"join works correctly IV")
|
||||
(assert-equal test
|
||||
"hello there world"
|
||||
&(join-with-char \ &[@"hello" @"there" @"world"])
|
||||
@ -218,6 +222,10 @@
|
||||
"hello, there, world"
|
||||
&(join-with-char \, &[@"hello" @" there" @" world"])
|
||||
"join-with-char works correctly II")
|
||||
(assert-equal test
|
||||
""
|
||||
&(join-with-char \, &[])
|
||||
"join-with-char works correctly III")
|
||||
(assert-equal test
|
||||
"hellohellohello"
|
||||
&(repeat 3 "hello")
|
||||
|
Loading…
Reference in New Issue
Block a user