mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 14:50:56 +00:00
lib/util: Don't modify input in UniqueTrimmedStrings (#7288)
Also clarified the comment.
This commit is contained in:
parent
ffcb57580f
commit
9c88efd55f
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user