mixedArrayFromString is the inverse of stringFromMixedArray. It splits a string to a series of either UTF-8 strings and non-UTF-8 bytes.
(s string)
| 382 | // splits a string to a series of either UTF-8 strings and non-UTF-8 |
| 383 | // bytes. |
| 384 | func mixedArrayFromString(s string) (parts []interface{}) { |
| 385 | for len(s) > 0 { |
| 386 | if n := utf8StrLen(s); n > 0 { |
| 387 | parts = append(parts, s[:n]) |
| 388 | s = s[n:] |
| 389 | } else { |
| 390 | parts = append(parts, s[0]) |
| 391 | s = s[1:] |
| 392 | } |
| 393 | } |
| 394 | return parts |
| 395 | } |
| 396 | |
| 397 | // utf8StrLen returns how many prefix bytes of s are valid UTF-8. |
| 398 | func utf8StrLen(s string) int { |