{"123", "", 2, []string{"1", "23"}},
{"123", "", 17, []string{"1", "2", "3"}},
{"bT", "T", math.MaxInt / 4, []string{"b", ""}},
+ {"\xff-\xff", "", -1, []string{"\xff", "-", "\xff"}},
+ {"\xff-\xff", "-", -1, []string{"\xff", "\xff"}},
}
func TestSplit(t *testing.T) {
// explode splits s into a slice of UTF-8 strings,
// one string per Unicode character up to a maximum of n (n < 0 means no limit).
-// Invalid UTF-8 sequences become correct encodings of U+FFFD.
+// Invalid UTF-8 bytes are sliced individually.
func explode(s string, n int) []string {
l := utf8.RuneCountInString(s)
if n < 0 || n > l {
}
a := make([]string, n)
for i := 0; i < n-1; i++ {
- ch, size := utf8.DecodeRuneInString(s)
+ _, size := utf8.DecodeRuneInString(s)
a[i] = s[:size]
s = s[size:]
- if ch == utf8.RuneError {
- a[i] = string(utf8.RuneError)
- }
}
if n > 0 {
a[n-1] = s
{"1 2 3 4", " ", 3, []string{"1", "2", "3 4"}},
{"1 2", " ", 3, []string{"1", "2"}},
{"", "T", math.MaxInt / 4, []string{""}},
+ {"\xff-\xff", "", -1, []string{"\xff", "-", "\xff"}},
+ {"\xff-\xff", "-", -1, []string{"\xff", "\xff"}},
}
func TestSplit(t *testing.T) {