-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
61 lines (49 loc) · 1.13 KB
/
utils.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
59
60
61
package main
import "strings"
// StringArrayContains checks if a value is within a string array.
func StringArrayContains(strings []string, str string) bool {
for _, cstr := range strings {
if str == cstr {
return true
}
}
return false
}
// Simple (if not efficient) function to determine if
// two string arrays contain the same data
func StringArrayEquals(a1, a2 []string) bool {
if a1 == nil && a2 == nil {
return true
}
if len(a1) != len(a2) {
return false
}
for _, s := range a1 {
if !StringArrayContains(a2, s) {
return false
}
}
return true
}
// returns an array of strings that are missing
func FindMissingStrings(strings, expectedStrings []string) []string {
if strings == nil || len(strings) == 0 {
return expectedStrings
}
var missingStrings = make([]string, len(expectedStrings))
var numStrings = 0
for _, s := range expectedStrings {
if !StringArrayContains(strings, s) {
missingStrings[numStrings] = s
numStrings++
}
}
if numStrings > 0 {
return missingStrings[0:numStrings]
} else {
return nil
}
}
func cleanName(name string) string {
return strings.ReplaceAll(name, "_", "-")
}