/// <summary> /// Find the end tag that lines up to the beginning tag. /// </summary> /// <param name="index">The index to start the search on. This specifies /// the starting data unit.</param> /// <param name="tag">The beginning tag that we are seeking the end tag /// for.</param> /// <returns>The index that the ending tag was found at. Returns -1 /// if not found.</returns> protected int FindEndTag(int index, Tag tag) { int depth = 0; int count = index; while (count < _page.getDataSize()) { DataUnit du = _page.GetDataUnit(count); if (du is TagDataUnit) { Tag nextTag = ((TagDataUnit)du).Tag; if (String.Compare(tag.Name, nextTag.Name, true) == 0) { if (nextTag.TagType == Tag.Type.End) { if (depth == 0) { return(count); } depth--; } else if (nextTag.TagType == Tag.Type.Begin) { depth++; } } } count++; } return(-1); }