Pull request: all: fix client custom upstream comments
Updates #2947. Squashed commit of the following: commit 498a05459b1aa00bcffee490acfeecb567025971 Merge: 6a7a2f8721e2c419Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Apr 13 13:40:29 2021 +0300 Merge branch 'master' into 2947-cli-ups-comment commit 6a7a2f87cfd2bdd829b82889890511fef8d84b9b Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Apr 13 13:34:28 2021 +0300 all: imp code, tests commit abc0be239f69cfc3e7d0cde2fc952d9157b2cd5d Merge: 82fb3fcb6410feebAuthor: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Tue Apr 13 13:17:09 2021 +0300 Merge branch 'master' into 2947-cli-ups-comment commit 82fb3fcb49cbc8d439cb5959c1cb84ae49b2257e Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 12 22:13:41 2021 +0300 all: fix client custom upstream comments
This commit is contained in:
@@ -19,6 +19,18 @@ func CloneSlice(a []string) (b []string) {
|
||||
return CloneSliceOrEmpty(a)
|
||||
}
|
||||
|
||||
// FilterOut returns a copy of strs with all strings for which f returned true
|
||||
// removed.
|
||||
func FilterOut(strs []string, f func(s string) (ok bool)) (filtered []string) {
|
||||
for _, s := range strs {
|
||||
if !f(s) {
|
||||
filtered = append(filtered, s)
|
||||
}
|
||||
}
|
||||
|
||||
return filtered
|
||||
}
|
||||
|
||||
// InSlice checks if string is in the slice of strings.
|
||||
func InSlice(strs []string, str string) (ok bool) {
|
||||
for _, s := range strs {
|
||||
@@ -30,6 +42,12 @@ func InSlice(strs []string, str string) (ok bool) {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCommentOrEmpty returns true of the string starts with a "#" character or is
|
||||
// an empty string.
|
||||
func IsCommentOrEmpty(s string) (ok bool) {
|
||||
return len(s) == 0 || s[0] == '#'
|
||||
}
|
||||
|
||||
// SplitNext splits string by a byte and returns the first chunk skipping empty
|
||||
// ones. Whitespaces are trimmed.
|
||||
func SplitNext(s *string, sep rune) (chunk string) {
|
||||
|
||||
@@ -36,6 +36,21 @@ func TestCloneSlice_family(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestFilterOut(t *testing.T) {
|
||||
strs := []string{
|
||||
"1.2.3.4",
|
||||
"",
|
||||
"# 5.6.7.8",
|
||||
}
|
||||
|
||||
want := []string{
|
||||
"1.2.3.4",
|
||||
}
|
||||
|
||||
got := FilterOut(strs, IsCommentOrEmpty)
|
||||
assert.Equal(t, want, got)
|
||||
}
|
||||
|
||||
func TestInSlice(t *testing.T) {
|
||||
simpleStrs := []string{"1", "2", "3"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user