forked from spring2go/gravitee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
string.go
40 lines (34 loc) · 1009 Bytes
/
string.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
package util
import (
"strings"
)
// StringInSlice is a function similar to "x in y" Python construct
func StringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
// SpaceDelimitedStringNotGreater returns true if the first string
// is the same as the second string or does not contain any substring
// not contained in the second string (when split by space)
func SpaceDelimitedStringNotGreater(first, second string) bool {
// Empty string is never greater
if first == "" {
return true
}
// Split the second string by space
secondParts := strings.Split(second, " ")
// Iterate over space delimited parts of the first string
for _, firstPart := range strings.Split(first, " ") {
// If the substring is not part of the second string, return false
if !StringInSlice(firstPart, secondParts) {
return false
}
}
// The first string is the same or more restrictive
// than the second string, return true
return true
}