Skip to content

Commit 08a61a6

Browse files
Merge pull request #446 from projectdiscovery/add_containsall_func
add `stringsutil.ContainsAll` func
2 parents 23cc2c3 + 0b2dedf commit 08a61a6

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

strings/stringsutil.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,13 @@ func IndexAny(s string, seps ...string) (int, string) {
302302
}
303303
return -1, ""
304304
}
305+
306+
// ContainsAll returns true if s contains all specified substrings.
307+
func ContainsAll(s string, ss ...string) bool {
308+
for _, sub := range ss {
309+
if !strings.Contains(s, sub) {
310+
return false
311+
}
312+
}
313+
return true
314+
}

strings/stringsutil_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,20 @@ func TestIndexAny(t *testing.T) {
390390
require.Equal(t, test.expectedSep, sep)
391391
}
392392
}
393+
394+
func TestContainsAll(t *testing.T) {
395+
tests := []struct {
396+
s string
397+
ss []string
398+
result bool
399+
}{
400+
{"abcdefg", []string{"a", "b"}, true},
401+
{"abcdefg", []string{"a", "z"}, false},
402+
{"abcdefg", []string{"a", "b", "c", "d", "e", "f", "g"}, true},
403+
{"abcdefg", []string{"a", "b", "c", "d", "e", "f", "g", "z"}, false},
404+
}
405+
for _, test := range tests {
406+
res := ContainsAll(test.s, test.ss...)
407+
require.Equal(t, test.result, res)
408+
}
409+
}

0 commit comments

Comments
 (0)