-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.go
54 lines (47 loc) · 980 Bytes
/
utilities.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
package main
import "regexp"
func isStringInSlice(str string, slice []string) bool {
for _, v := range slice {
if v == str {
return true
}
}
return false
}
func stringOccurencesInSlice(str string, slice []string) int {
count := 0
for _, v := range slice {
if v == str {
count++
}
}
return count
}
func uniqueSlice(slice *[]string) {
uniqueSlice := make(map[string]struct{}, len(*slice))
j := 0
for _, string := range *slice {
if _, seen := uniqueSlice[string]; seen {
continue
}
uniqueSlice[string] = struct{}{}
(*slice)[j] = string
j++
}
*slice = (*slice)[:j]
}
func removeStringFromSlice(str string, slice *[]string) {
i := stringIndexOfSlice(str, *slice)
*slice = append((*slice)[:i], (*slice)[i+1:]...)
}
func stringIndexOfSlice(str string, slice []string) int {
for i, v := range slice {
if v == str {
return i
}
}
return -1
}
func stringMatchesRegex(str string, r *regexp.Regexp) bool {
return r.MatchString(str)
}