-
Notifications
You must be signed in to change notification settings - Fork 57
/
util.go
58 lines (49 loc) · 879 Bytes
/
util.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
56
57
58
package creeper
import (
"crypto/md5"
"encoding/hex"
"regexp"
)
func stringsMap(l []string, cb func(string) string) []string {
nl := []string{}
for i := range l {
nl = append(nl, cb(l[i]))
}
return nl
}
func stringsFilter(l []string, cb func(string) bool) []string {
nl := []string{}
for _, e := range l {
if cb(e) {
nl = append(nl, e)
}
}
return nl
}
func stringsMatch(l []string, r *regexp.Regexp) []string {
return stringsFilter(l, func(s string) bool {
return r.MatchString(s)
})
}
func MD5(s string) string {
m := md5.New()
m.Write([]byte(s))
return hex.EncodeToString(m.Sum(nil))
}
type MonoStack struct {
value string
has bool
}
func (o *MonoStack) Set(s string) {
o.value = s
o.has = true
}
func (o *MonoStack) Has() bool {
return o.has
}
func (o *MonoStack) Value() string {
o.has = false
s := o.value
o.value = ""
return s
}