lib/util: Don't modify input in UniqueTrimmedStrings (#7288)

Also clarified the comment.
This commit is contained in:
greatroar 2021-01-16 17:39:15 +01:00 committed by GitHub
parent ffcb57580f
commit 9c88efd55f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -119,16 +119,14 @@ func CopyMatchingTag(from interface{}, to interface{}, tag string, shouldCopy fu
}
}
// UniqueTrimmedStrings returns a list on unique strings, trimming at the same time.
// UniqueTrimmedStrings returns a list of all unique strings in ss,
// in the order in which they first appear in ss, after trimming away
// leading and trailing spaces.
func UniqueTrimmedStrings(ss []string) []string {
// Trim all first
for i, v := range ss {
ss[i] = strings.Trim(v, " ")
}
var m = make(map[string]struct{}, len(ss))
var us = make([]string, 0, len(ss))
for _, v := range ss {
v = strings.Trim(v, " ")
if _, ok := m[v]; ok {
continue
}