Microsoft.Html.Core.Tree.Nodes.ElementNode.FindTopmostParent C# (CSharp) Method

FindTopmostParent() private method

Given list of end tag names finds topmost element that matches provided end tags
private FindTopmostParent ( List tagNames, bool ignoreCase ) : ElementNode
tagNames List
ignoreCase bool
return ElementNode
        internal ElementNode FindTopmostParent(List<string> tagNames, bool ignoreCase) {
            ElementNode topmostNode = this;
            var node = this;

            if (tagNames.Count > 1)
                return Root; // Edge case, can be optimized later if necessary.

            foreach (string tag in tagNames) {
                while (!(node is RootNode)) {
                    if (String.Compare(tag, node.QualifiedName, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0) {
                        topmostNode = node.Parent;

                        // Don't break and instead continue up to the topmost
                        // matching node so we properly handle insertion of </a>
                        // into the innermost element in <a><a><a>|</a></a></a>
                    }

                    node = node.Parent;
                }
            }

            return topmostNode;
        }