Commit 0cd87772 authored by Scott Lawrence's avatar Scott Lawrence Committed by Rob Pike

strings: fix Split("", "", -1)

Fixes #980.

Made it return an empty array, rather than crash.
Added relevant test cases to strings.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/1914041
parent b6c2bf71
......@@ -28,8 +28,10 @@ func explode(s string, n int) []string {
a[i] = string(rune)
cur += size
}
// add the rest
a[i] = s[cur:]
// add the rest, if there is any
if cur < len(s) {
a[i] = s[cur:]
}
return a
}
......
......@@ -109,6 +109,7 @@ type ExplodeTest struct {
}
var explodetests = []ExplodeTest{
ExplodeTest{"", -1, []string{}},
ExplodeTest{abcd, 4, []string{"a", "b", "c", "d"}},
ExplodeTest{faces, 3, []string{"☺", "☻", "☹"}},
ExplodeTest{abcd, 2, []string{"a", "bcd"}},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment