diff --git a/match.go b/match.go index 6581d99..0c88423 100644 --- a/match.go +++ b/match.go @@ -67,6 +67,12 @@ func PathMatch(pattern, name string) (bool, error) { return matchWithSeparator(pattern, name, filepath.Separator, true) } +// MatchWithSeparator returns true if `name` matches the file name `pattern` +// using the specified rune as separator. +func MatchWithSeparator(pattern, name string, separator rune) (bool, error) { + return matchWithSeparator(pattern, name, separator, true) +} + func matchWithSeparator(pattern, name string, separator rune, validate bool) (matched bool, err error) { return doMatchWithSeparator(pattern, name, separator, validate, -1, -1, -1, -1, 0, 0) } @@ -283,7 +289,7 @@ MATCH: } } - if validate && patIdx < patLen && !doValidatePattern(pattern[patIdx:], separator) { + if validate && patIdx < patLen && !ValidateWithSeparator(pattern[patIdx:], separator) { return false, ErrBadPattern } return false, nil @@ -334,7 +340,7 @@ func isZeroLengthPattern(pattern string, separator rune) (ret bool, err error) { } // no luck - validate the rest of the pattern - if !doValidatePattern(pattern, separator) { + if !ValidateWithSeparator(pattern, separator) { return false, ErrBadPattern } return false, nil diff --git a/validate.go b/validate.go index c689b9e..b9a5a08 100644 --- a/validate.go +++ b/validate.go @@ -11,7 +11,7 @@ import "path/filepath" // ValidatePattern assumes your pattern uses '/' as the path separator. // func ValidatePattern(s string) bool { - return doValidatePattern(s, '/') + return ValidateWithSeparator(s, '/') } // Like ValidatePattern, only uses your OS path separator. In other words, use @@ -20,10 +20,11 @@ func ValidatePattern(s string) bool { // Glob() requires '/' separators, even if your OS uses something else. // func ValidatePathPattern(s string) bool { - return doValidatePattern(s, filepath.Separator) + return ValidateWithSeparator(s, filepath.Separator) } -func doValidatePattern(s string, separator rune) bool { +// ValidateWithSeparator is like ValidatePattern using the specified separator. +func ValidateWithSeparator(s string, separator rune) bool { altDepth := 0 l := len(s) VALIDATE: