(a []Text)
| 92 | } |
| 93 | |
| 94 | func 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 | // 返回多个字元的字节总长度 |
| 123 | func textSliceByteLength(text []Text) (length int) { |
no outgoing calls