2023-11-07 16:53:23 +00:00
|
|
|
package util
|
2023-10-17 14:10:48 +00:00
|
|
|
|
|
|
|
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.
|
2023-11-07 16:53:23 +00:00
|
|
|
func GlobMatch(s, pattern string) bool {
|
2023-10-17 14:10:48 +00:00
|
|
|
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])
|
|
|
|
}
|
|
|
|
}
|