1- using System ;
2- using System . Text ;
3- using DotNet . Globbing . Token ;
1+ using DotNet . Globbing . Token ;
42
53namespace DotNet . Globbing . Evaluation
64{
@@ -31,35 +29,49 @@ public bool IsMatch(string allChars, int currentPosition, out int newPosition)
3129 newPosition = currentPosition ;
3230
3331 // 1. Are we already at the end of the test string?
34- if ( currentPosition >= allChars . Length )
32+ if ( currentPosition >= allChars . Length - 1 )
3533 {
3634 return true ;
3735 }
3836
3937 // A) If leading seperator then current character needs to be that seperator.
40- var currentChar = allChars [ currentPosition ] ;
41- if ( this . _token . LeadingPathSeperator != null )
38+ char currentChar = allChars [ currentPosition ] ;
39+ if ( _token . LeadingPathSeperator != null )
4240 {
4341 if ( ! GlobStringReader . IsPathSeperator ( currentChar ) )
4442 {
4543 // expected seperator.
4644 return false ;
4745 }
48-
46+ //else
47+ //{
4948 // advance current position to match the leading seperator.
5049 currentPosition = currentPosition + 1 ;
50+ //}
51+ }
52+ else
53+ {
54+ // no leading seperator, means ** used at start of pattern not /** used within pattern.
55+ // If **/ is used for start of pattern then input string doesn't need to start with a / or \ and it will be matched.
56+ // i.e **/foo/bar will match foo/bar or /foo/bar.
57+ // where as /**/foo/bar will not match foo/bar it will only match /foo/bar.
58+ if ( GlobStringReader . IsPathSeperator ( currentChar ) )
59+ {
60+ // advance current position to match the leading seperator.
61+ currentPosition = currentPosition + 1 ;
62+ }
5163 }
5264
5365 // 2. if no more tokens require matching (i.e ** is the last token) - we match.
54- if ( this . _subEvaluator . EvaluatorCount == 0 )
66+ if ( _subEvaluator . EvaluatorCount == 0 )
5567 {
5668 newPosition = allChars . Length ;
5769 return true ;
5870 }
5971
6072 // Because we know we have more tokens in the pattern (subevaluators) - those will require a minimum amount of characters to match (could be 0 too).
6173 // We can therefore calculate a "max" character position that we can match to, as if we exceed that position the remaining tokens cant possibly match.
62- var maxPos = ( allChars . Length - _subEvaluator . ConsumesMinLength ) ;
74+ int maxPos = ( allChars . Length - _subEvaluator . ConsumesMinLength ) ;
6375
6476 // If all of the remaining tokens have a precise length, we can calculate the exact character that we need to macth to in the string.
6577 // Otherwise we have to test at multiple character positions until we find a match (less efficient)
@@ -69,12 +81,12 @@ public bool IsMatch(string allChars, int currentPosition, out int newPosition)
6981 // As we can only match full segments, make sure character before chacracter at max pos is a seperator,
7082 if ( maxPos > 0 )
7183 {
72- var mustMatchUntilChar = allChars [ maxPos - 1 ] ;
84+ char mustMatchUntilChar = allChars [ maxPos - 1 ] ;
7385 if ( ! GlobStringReader . IsPathSeperator ( mustMatchUntilChar ) )
7486 {
7587 // can only match full segments.
7688 return false ;
77- }
89+ }
7890 }
7991
8092 // Advance position to max pos.
@@ -90,6 +102,7 @@ public bool IsMatch(string allChars, int currentPosition, out int newPosition)
90102 currentChar = allChars [ currentPosition ] ;
91103
92104 // If the ** token was parsed with a trailing slash - i.e "**/" then we need to match past it before we test remainijng tokens.
105+ // special exception if **/ is at start of pattern, as then the input string need not have any path seperators.
93106 if ( _token . TrailingPathSeperator != null )
94107 {
95108 if ( GlobStringReader . IsPathSeperator ( currentChar ) )
@@ -125,7 +138,7 @@ public bool IsMatch(string allChars, int currentPosition, out int newPosition)
125138 // match the seperator.
126139 currentPosition = currentPosition + 1 ;
127140 break ;
128- }
141+ }
129142 }
130143 }
131144 }
@@ -134,15 +147,9 @@ public bool IsMatch(string allChars, int currentPosition, out int newPosition)
134147
135148 }
136149
137- public virtual int ConsumesMinLength
138- {
139- get { return _subEvaluator . ConsumesMinLength ; }
140- }
150+ public virtual int ConsumesMinLength => _subEvaluator . ConsumesMinLength ;
141151
142- public bool ConsumesVariableLength
143- {
144- get { return true ; }
145- }
152+ public bool ConsumesVariableLength => true ;
146153
147154 #endregion
148155
0 commit comments