Add CopyOf utility method
Add a utility method that returns a copy of a slice of strings. This is primarily useful when appending to a string slice to avoid accidentally reusing the backing array. Test: util_test.go Change-Id: I7801fc7ca19e27ddc9f1b1b452788b723c7f619c
This commit is contained in:
@@ -20,6 +20,11 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CopyOf returns a new slice that has the same contents as s.
|
||||
func CopyOf(s []string) []string {
|
||||
return append([]string(nil), s...)
|
||||
}
|
||||
|
||||
func JoinWithPrefix(strs []string, prefix string) string {
|
||||
if len(strs) == 0 {
|
||||
return ""
|
||||
|
Reference in New Issue
Block a user