-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfilter.go
55 lines (51 loc) · 962 Bytes
/
filter.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
54
55
package logpeck
import (
"strings"
)
// PeckFilter .
type PeckFilter struct {
incl []string
excl []string
haveIncl bool
haveExcl bool
}
// NewPeckFilter .
func NewPeckFilter(Keywords string) *PeckFilter {
filter := &PeckFilter{haveIncl: false, haveExcl: false}
substrs := strings.Split(Keywords, "|")
for _, substr := range substrs {
if substr == "" {
continue
}
if substr[0] == '^' {
filter.excl = append(filter.excl, substr[1:])
filter.haveExcl = true
} else {
filter.incl = append(filter.incl, substr)
filter.haveIncl = true
}
}
return filter
}
// Drop return true if do not need processing
func (p *PeckFilter) Drop(str string) bool {
res := false
for _, f := range p.incl {
if strings.Contains(str, f) {
res = false
break
} else {
res = true
}
}
if res {
return true
}
for _, f := range p.excl {
if strings.Contains(str, f) {
return true
}
}
SplitString("", "")
return false
}