Skip to content

Commit

Permalink
Fixes #20
Browse files Browse the repository at this point in the history
Underscore and colon's not read.
Issue with pattern not matching when last segment of pattern ends with a * and the string being matched contains more characters for that * to match on.
  • Loading branch information
dazinator committed Mar 6, 2017
1 parent c610aab commit 289b206
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/DotNet.Glob/Evaluation/CompositeTokenEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ public bool IsMatch(string allChars, int currentPosition, out int newPosition)
return false;
}

//if (_Evaluators.Count == 0)
//{
// // no sub evaluators in this composite.
// // happens for wildcards that are at the end of a pattern.
// return true;
//}

foreach (var matcher in _Evaluators)
{
if (!matcher.IsMatch(allChars, newPosition, out newPosition))
Expand All @@ -135,6 +142,8 @@ public bool IsMatch(string allChars, int currentPosition, out int newPosition)

public bool ConsumesVariableLength { get; protected set; }

public int EvaluatorCount { get { return _Evaluators.Count; } }

protected void AddEvaluator(IGlobTokenEvaluator evaluator)
{
_Evaluators.Add(evaluator);
Expand Down
32 changes: 31 additions & 1 deletion src/DotNet.Glob/Evaluation/WildcardTokenEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ public class WildcardTokenEvaluator : IGlobTokenEvaluator
private readonly WildcardToken _token;
//private readonly IGlobToken[] _subTokens;
private readonly CompositeTokenEvaluator _subEvaluator;
private readonly bool _requiresSubEvaluation;

public WildcardTokenEvaluator(WildcardToken token, CompositeTokenEvaluator subEvaluator)
{
_token = token;
_subEvaluator = subEvaluator;
_requiresSubEvaluation = _subEvaluator.EvaluatorCount > 0;
}

#region IGlobTokenEvaluator
Expand All @@ -22,6 +24,33 @@ public bool IsMatch(string allChars, int currentPosition, out int newPosition)
{

newPosition = currentPosition;

// If the glob is last in a pattern, there is no remaining patterns that need matching.
// In that case we just match every thing until we reach a seperator, at which point we fail.

if (!_requiresSubEvaluation)
{
// if we are at the end of the string, we match!
if (currentPosition >= allChars.Length)
{
return true;
}

for (int i = currentPosition; i <= allChars.Length -1; i++)
{
var currentChar = allChars[i];
if (currentChar == '/' || currentChar == '\\')
{
return false;
}
}

newPosition = currentPosition + allChars.Length;
return true;

}

// We have remaining pattern to evaluate.
if (!_subEvaluator.ConsumesVariableLength)
{
// The remaining tokens match against a fixed length string, so wildcard **must** consume
Expand Down Expand Up @@ -54,7 +83,8 @@ public bool IsMatch(string allChars, int currentPosition, out int newPosition)
if (currentChar == '/' || currentChar == '\\')
{
return false;
}
}


//int newSubPosition;
var isMatch = _subEvaluator.IsMatch(allChars, i, out newPosition);
Expand Down
2 changes: 1 addition & 1 deletion src/DotNet.Glob/GlobStringReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class GlobStringReader : StringReader
//public const char HashChar = '#';


public static char[] AllowedNonAlphaNumericChars = new[] { '.', ' ', '!', '#', '-', ';', '=', '@', '~' };
public static char[] AllowedNonAlphaNumericChars = new[] { '.', ' ', '!', '#', '-', ';', '=', '@', '~', '_',':' };

/// <summary>
/// The current delimiters
Expand Down

0 comments on commit 289b206

Please sign in to comment.