MCPcopy
hub / github.com/perkeep/perkeep / mixedArrayFromString

Function mixedArrayFromString

pkg/schema/schema.go:384–395  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

382// splits a string to a series of either UTF-8 strings and non-UTF-8
383// bytes.
384func 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.
398func utf8StrLen(s string) int {

Callers 3

TestMixedArrayFromStringFunction · 0.85
SetFileNameMethod · 0.85
SetSymlinkTargetMethod · 0.85

Calls 1

utf8StrLenFunction · 0.85

Tested by 1

TestMixedArrayFromStringFunction · 0.68