MCPcopy Index your code
hub / github.com/huichen/sego / Join

Function Join

utils.go:94–120  ·  view source on GitHub ↗
(a []Text)

Source from the content-addressed store, hash-verified

92}
93
94func Join(a []Text) string {
95 switch len(a) {
96 case 0:
97 return ""
98 case 1:
99 return string(a[0])
100 case 2:
101 // Special case for common small values.
102 // Remove if golang.org/issue/6714 is fixed
103 return string(a[0]) + string(a[1])
104 case 3:
105 // Special case for common small values.
106 // Remove if golang.org/issue/6714 is fixed
107 return string(a[0]) + string(a[1]) + string(a[2])
108 }
109 n := 0
110 for i := 0; i < len(a); i++ {
111 n += len(a[i])
112 }
113
114 b := make([]byte, n)
115 bp := copy(b, a[0])
116 for _, s := range a[1:] {
117 bp += copy(b[bp:], s)
118 }
119 return string(b)
120}
121
122// 返回多个字元的字节总长度
123func textSliceByteLength(text []Text) (length int) {

Callers 3

Test_textSliceToStringFunction · 0.85
StringsJoinFunction · 0.85
textSliceToStringFunction · 0.85

Calls

no outgoing calls

Tested by 2

Test_textSliceToStringFunction · 0.68
StringsJoinFunction · 0.68