/// <summary> /// Parses the given path and converts the various ** and * elements into /// regular expressions for selection. /// </summary> private void ParseSelectors() { // Create a selector regex that matches the length. operations = new object[Levels.Count]; for (int index = 0; index < Levels.Count; index++) { // Check for "**" by itself which means zero or more levels. string level = Levels[index]; if (level == "**") { // Create a sub-tree of the selector and put it into this // object. operations[index] = new HierarchicalSelector(Levels, index + 1, true); continue; } // Check for globbing operators ("*") which become ".*?" regex. if (level.Contains("*")) { // Go through the string and convert all the "*" into regex. var buffer = new StringBuilder(); for (int c = 0; c < level.Length; c++) { if (level[c] == '*') { buffer.Append(".*?"); } else { buffer.Append(level[c]); } } operations[index] = new Regex(buffer.ToString()); continue; } // For everything else, leave it null to indicate that a strict // string is required. operations[index] = null; } }
public void TestSingleStarMatch3() { var nr = new HierarchicalSelector("/*/*/*/c"); Assert.IsFalse(nr.IsMatch("/a/b/c")); }
public void TestDoubleStarMatch() { var nr = new HierarchicalSelector("/**/c"); Assert.IsTrue(nr.IsMatch("/a/b/c")); }