forked from projectdiscovery/subfinder
/
stringset.go
53 lines (45 loc) · 985 Bytes
/
stringset.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// StringSet Code taken from Gobuster
// Written By OJ Reeves. All thank goes to him :-)
// Hope he doesn't minds
package helper
import (
"strings"
)
// Shim type for "set" containing strings
type StringSet struct {
Set map[string]bool
}
// Add an element to a set
func (set *StringSet) Add(s string) bool {
_, found := set.Set[s]
set.Set[s] = true
return !found
}
// Add a list of elements to a set
func (set *StringSet) AddRange(ss []string) {
for _, s := range ss {
set.Set[s] = true
}
}
// Test if an element is in a set
func (set *StringSet) Contains(s string) bool {
_, found := set.Set[s]
return found
}
// Check if any of the elements exist
func (set *StringSet) ContainsAny(ss []string) bool {
for _, s := range ss {
if set.Set[s] {
return true
}
}
return false
}
// Stringify the set
func (set *StringSet) Stringify() string {
values := []string{}
for s, _ := range set.Set {
values = append(values, s)
}
return strings.Join(values, ",")
}