private static void DisplayGroups(NMatchesEventArgs args, Match match, TreeNode MatchRoot) { const int DEFAULT_GROUP_INDEX = 1; if (match.Groups.Count <= DEFAULT_GROUP_INDEX) { return; } for (int i = DEFAULT_GROUP_INDEX; i < match.Groups.Count; i++) { Group group = match.Groups[i]; string groupName = args.RegexInstance.GroupNameFromNumber(i); string finalNodeText = string.Empty; if (groupName != string.Empty) { finalNodeText = string.Format("{1}:[{0}]", group.Value, groupName); } else { finalNodeText = string.Format("{1}:[{0}]", group.Value, i); } TreeNode groupRoot = new TreeNode(finalNodeText); MatchRoot.Nodes.Add(groupRoot); DisplayCaptures(group, groupRoot); } }
private static NMatchesEventArgs createNMatchesArgs(string pattern, string input) { NMatchesEventArgs args = new NMatchesEventArgs(); args.RegexInstance = new ExtendedRegex(pattern); args.Matches = args.RegexInstance.Matches(input); return(args); }
public void TreeShowsOneMatchWithGroupNameIfExists() { MatchesTree mt = new MatchesTree(); TreeView tree = mt.TreeView; NMatchesEventArgs args = createNMatchesArgs(@"(?<group>a)", "a"); mt.Display(args); Assert.AreEqual("group:[a]", tree.Nodes[0].Nodes[0].Text); }
public void TreeShowsOneMatchTextNoBracesIfNoGroupName() { MatchesTree mt = new MatchesTree(); TreeView tree = mt.TreeView; NMatchesEventArgs args = createNMatchesArgs("a", "a"); mt.Display(args); Assert.AreEqual("[a]", tree.Nodes[0].Text); }
public void TreeShowsOneMatchNodeOnOneMatch() { MatchesTree mt = new MatchesTree(); TreeView tree = mt.TreeView; NMatchesEventArgs args = createNMatchesArgs("a", "a"); mt.Display(args); Assert.AreEqual(1, tree.Nodes.Count); }
public override void ExecuteMatches() { ExtendedRegex regex = getRegex(); MatchCollection matches = regex.Matches(InputText); foreach (IRegexView view in m_views) { NMatchesEventArgs args = new NMatchesEventArgs(); args.Matches = matches; args.RegexInstance = regex; view.OnMatches(args); } }
public void Display(NMatchesEventArgs args) { if (args.Matches == null) { return; } foreach (Match match in args.Matches) { string prefix = string.Empty; TreeNode MatchRoot = new TreeNode(string.Format("[{0}]", match.Value)); tree.Nodes.Add(MatchRoot); DisplayGroups(args, match, MatchRoot); MatchRoot.Expand(); } }