private void AddLiteralNodes(RegexResultTreeNode regexResultTreeNode, string toMatch) { int currentIndex = regexResultTreeNode.StartIndex; List <LiteralNode> literalNodes = new List <LiteralNode>(); foreach (RegexResultTreeNode child in regexResultTreeNode.ChildNodes) { AddLiteralNode(literalNodes, currentIndex, child.StartIndex, toMatch); AddLiteralNodes(child, toMatch); currentIndex = child.EndIndex; } AddLiteralNode(literalNodes, currentIndex, regexResultTreeNode.EndIndex, toMatch); foreach (LiteralNode literalNode in literalNodes) { regexResultTreeNode.AddChildNode(literalNode); } }
public int CompareTo(object obj) { RegexResultTreeNode other = obj as RegexResultTreeNode; if (this.StartIndex < other.StartIndex) { return(-1); } if (other.StartIndex < this.StartIndex) { return(1); } if (this.EndIndex < other.EndIndex) { return(-1); } if (other.EndIndex < this.EndIndex) { return(1); } return(0); }
private void AddRegexResultTreeNode(RegexResultTreeNode parent, RegexResultTreeNode child) { List <RegexResultTreeNode> toRemove = new List <RegexResultTreeNode>(); foreach (RegexResultTreeNode otherNode in parent.ChildNodes) { if (child.IsChildOf(otherNode)) { AddRegexResultTreeNode(otherNode, child); return; } else if (otherNode.IsChildOf(child)) { toRemove.Add(otherNode); child.AddChildNode(otherNode); } } foreach (RegexResultTreeNode node in toRemove) { parent.RemoveChildNode(node); } parent.AddChildNode(child); }
public bool IsChildOf(RegexResultTreeNode other) { return(this.StartIndex >= other.StartIndex && this.EndIndex <= other.EndIndex); }
public void RemoveChildNode(RegexResultTreeNode child) { children.Remove(child); }
public void AddChildNode(RegexResultTreeNode child) { children.Add(child, child); }