2022-03-30 20:36:25 +02:00
|
|
|
package list
|
|
|
|
|
2022-07-21 20:23:00 +02:00
|
|
|
const All = "*"
|
|
|
|
|
2022-03-30 20:36:25 +02:00
|
|
|
// Contains tests if a string is contained in the list.
|
|
|
|
func Contains(list []string, s string) bool {
|
|
|
|
if len(list) == 0 || s == "" {
|
|
|
|
return false
|
2022-07-21 20:23:00 +02:00
|
|
|
} else if s == All {
|
2022-03-30 20:36:25 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find matches.
|
|
|
|
for i := range list {
|
2022-07-21 20:23:00 +02:00
|
|
|
if s == list[i] || list[i] == All {
|
2022-03-30 20:36:25 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// ContainsAny tests if two lists have at least one common entry.
|
|
|
|
func ContainsAny(l, s []string) bool {
|
|
|
|
if len(l) == 0 || len(s) == 0 {
|
|
|
|
return false
|
2022-07-21 20:23:00 +02:00
|
|
|
} else if s[0] == All {
|
2022-03-30 20:36:25 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find matches.
|
|
|
|
for i := range l {
|
|
|
|
for j := range s {
|
2022-07-21 20:23:00 +02:00
|
|
|
if s[j] == l[i] || s[j] == All {
|
2022-03-30 20:36:25 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nothing found.
|
|
|
|
return false
|
|
|
|
}
|