Skip to content

Commit

Permalink
Merge pull request #452 from projectdiscovery/add_containsalli_func
Browse files Browse the repository at this point in the history
add `stringsutil.ContainsAllI` func
  • Loading branch information
Mzack9999 authored Jun 25, 2024
2 parents 08a61a6 + ba95de8 commit 7720027
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions strings/stringsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,14 @@ func ContainsAll(s string, ss ...string) bool {
}
return true
}

// ContainsAllI returns true if s contains all specified substrings (case-insensitive).
func ContainsAllI(s string, ss ...string) bool {
lowerS := strings.ToLower(s)
for _, sub := range ss {
if !strings.Contains(lowerS, strings.ToLower(sub)) {
return false
}
}
return true
}
17 changes: 17 additions & 0 deletions strings/stringsutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,20 @@ func TestContainsAll(t *testing.T) {
require.Equal(t, test.result, res)
}
}

func TestContainsAllI(t *testing.T) {
tests := []struct {
s string
ss []string
result bool
}{
{"abcdefg", []string{"A", "b"}, true},
{"abcdefg", []string{"A", "z"}, false},
{"abcdefg", []string{"A", "b", "c", "d", "e", "f", "g"}, true},
{"abcdefg", []string{"A", "b", "c", "d", "e", "f", "g", "z"}, false},
}
for _, test := range tests {
res := ContainsAllI(test.s, test.ss...)
require.Equal(t, test.result, res)
}
}

0 comments on commit 7720027

Please sign in to comment.