github.com/fufuok/balancer@v1.0.0/utils/string.go (about)

     1  package utils
     2  
     3  // AddStringBytes 拼接字符串, 返回 bytes from bytes.Join()
     4  func AddStringBytes(s ...string) []byte {
     5  	switch len(s) {
     6  	case 0:
     7  		return []byte{}
     8  	case 1:
     9  		return []byte(s[0])
    10  	}
    11  
    12  	n := 0
    13  	for _, v := range s {
    14  		n += len(v)
    15  	}
    16  
    17  	b := make([]byte, n)
    18  	bp := copy(b, s[0])
    19  	for _, v := range s[1:] {
    20  		bp += copy(b[bp:], v)
    21  	}
    22  
    23  	return b
    24  }
    25  
    26  // AddString 拼接字符串
    27  func AddString(s ...string) string {
    28  	switch len(s) {
    29  	case 0:
    30  		return ""
    31  	case 1:
    32  		return s[0]
    33  	default:
    34  		return B2S(AddStringBytes(s...))
    35  	}
    36  }