2020-10-02 01:57:11 +02:00
|
|
|
package pattern
|
|
|
|
|
2021-01-05 00:01:39 +01:00
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
)
|
2020-10-02 01:57:11 +02:00
|
|
|
|
|
|
|
// Match checks whether a string matches a pattern
|
|
|
|
func Match(pattern, s string) bool {
|
|
|
|
if pattern == "*" {
|
|
|
|
return true
|
|
|
|
}
|
2021-01-05 00:01:39 +01:00
|
|
|
// Backslashes break filepath.Match, so we'll remove all of them.
|
|
|
|
// This has a pretty significant impact on performance when there
|
|
|
|
// are backslashes, but at least it doesn't break filepath.Match.
|
|
|
|
s = strings.ReplaceAll(s, "\\", "")
|
2020-10-02 01:57:11 +02:00
|
|
|
matched, _ := filepath.Match(pattern, s)
|
|
|
|
return matched
|
|
|
|
}
|