forked from TrueCloudLab/policy-engine
a064a01fdb
Signed-off-by: Airat Arifullin <aarifullin@yadro.com>
22 lines
504 B
Go
22 lines
504 B
Go
package util
|
|
|
|
import (
|
|
"strings"
|
|
"unicode/utf8"
|
|
)
|
|
|
|
// Matches s against the pattern.
|
|
// ? in pattern correspond to any symbol.
|
|
// * in pattern correspond to any sequence of symbols.
|
|
// Currently only '*' in the suffix is supported.
|
|
func GlobMatch(s, pattern string) bool {
|
|
index := strings.IndexByte(pattern, '*')
|
|
switch index {
|
|
default:
|
|
panic("unimplemented")
|
|
case -1:
|
|
return pattern == s
|
|
case utf8.RuneCountInString(pattern) - 1:
|
|
return strings.HasPrefix(s, pattern[:len(pattern)-1])
|
|
}
|
|
}
|