github.com/jxgolibs/go-oauth2-server@v1.0.1/util/string.go (about) 1 package util 2 3 import ( 4 "strings" 5 ) 6 7 // StringInSlice is a function similar to "x in y" Python construct 8 func StringInSlice(a string, list []string) bool { 9 for _, b := range list { 10 if b == a { 11 return true 12 } 13 } 14 return false 15 } 16 17 // SpaceDelimitedStringNotGreater returns true if the first string 18 // is the same as the second string or does not contain any substring 19 // not contained in the second string (when split by space) 20 func SpaceDelimitedStringNotGreater(first, second string) bool { 21 // Empty string is never greater 22 if first == "" { 23 return true 24 } 25 26 // Split the second string by space 27 secondParts := strings.Split(second, " ") 28 29 // Iterate over space delimited parts of the first string 30 for _, firstPart := range strings.Split(first, " ") { 31 // If the substring is not part of the second string, return false 32 if !StringInSlice(firstPart, secondParts) { 33 return false 34 } 35 } 36 37 // The first string is the same or more restrictive 38 // than the second string, return true 39 return true 40 }