@@ -53,6 +53,17 @@ func Match(pattern, name string) (bool, error) {
5353 return matchWithSeparator (pattern , name , '/' , true )
5454}
5555
56+ // MatchUnvalidated can provide a small performance improvement if you don't
57+ // care about whether or not the pattern is valid (perhaps because you already
58+ // ran `ValidatePattern`). Note that there's really only one case where this
59+ // performance improvement is realized: when pattern matching reaches the end
60+ // of `name` before reaching the end of `pattern`, such as `Match("a/b/c",
61+ // "a")`.
62+ func MatchUnvalidated (pattern , name string ) bool {
63+ matched , _ := matchWithSeparator (pattern , name , '/' , false )
64+ return matched
65+ }
66+
5667// PathMatch returns true if `name` matches the file name `pattern`. The
5768// difference between Match and PathMatch is that PathMatch will automatically
5869// use your system's path separator to split `name` and `pattern`. On systems
@@ -67,6 +78,17 @@ func PathMatch(pattern, name string) (bool, error) {
6778 return matchWithSeparator (pattern , name , filepath .Separator , true )
6879}
6980
81+ // PathMatchUnvalidated can provide a small performance improvement if you
82+ // don't care about whether or not the pattern is valid (perhaps because you
83+ // already ran `ValidatePattern`). Note that there's really only one case where
84+ // this performance improvement is realized: when pattern matching reaches the
85+ // end of `name` before reaching the end of `pattern`, such as `Match("a/b/c",
86+ // "a")`.
87+ func PathMatchUnvalidated (pattern , name string ) bool {
88+ matched , _ := matchWithSeparator (pattern , name , filepath .Separator , false )
89+ return matched
90+ }
91+
7092func matchWithSeparator (pattern , name string , separator rune , validate bool ) (matched bool , err error ) {
7193 return doMatchWithSeparator (pattern , name , separator , validate , - 1 , - 1 , - 1 , - 1 , 0 , 0 )
7294}
0 commit comments