/// <summary> /// Looks for the location of the next tag, starting at the specified position /// </summary> /// <returns>The position details of the next tag</returns> /// <param name="searchText">The text to search for tags</param> /// <param name="startPosition">The position within the text to start search for tags</param> /// <param name="tagName">The name of the tag to search for</param> private TagPosition FindTagPosition(string searchText, int startPosition, string tagName) { TagPosition tagPosition = null; string startTagText = "<!-- " + tagName + " "; int tagStartStartIndex = searchText.IndexOf(startTagText, startPosition, StringComparison.OrdinalIgnoreCase); if (tagStartStartIndex == -1) { return(null); // tag not found } string startTagEndText = " -->"; int tagStartEndIndex = searchText.IndexOf(startTagEndText, tagStartStartIndex, StringComparison.OrdinalIgnoreCase); if (tagStartEndIndex == -1) { this.BuildHandler.SignalBuildError(tagName + " tag not closed"); } tagPosition = new TagPosition(); tagPosition.StartPosition = tagStartStartIndex; tagPosition.StartEndPosition = tagStartStartIndex + startTagText.Length; tagPosition.EndPosition = tagStartEndIndex + startTagEndText.Length; return(tagPosition); }
/// <summary> /// Attempts to extract the the next tag, starting at the specified position /// </summary> /// <returns>True if a Tag was found</returns> /// <param name="tag">The Tag to find</param> /// <param name="currentPosition">The position to start looking at</param> private void ExtractTag(Tag tag, int currentPosition) { // Find the tag TagPosition startTagPosition = this.FindTagPosition(tag.SearchText, currentPosition, tag.Name + (tag.HasContent ? "_START" : "")); if (startTagPosition == null) { return; // Tag not found } tag.StartTagPosition = startTagPosition; // Extract the Tag values this.GetTagValues(tag); }
/// <summary> /// Locate the end tag and extract everything inbetween the start and end tags /// </summary> /// <param name="tag">The target tag</param> private void ExtractTagContent(Tag tag) { // Find the end tag string endTagName = tag.Name + "_END"; TagPosition endTagPosition = this.FindTagPosition(tag.SearchText, tag.StartTagPosition.EndPosition, endTagName); if (endTagPosition == null) { this.BuildHandler.SignalBuildError("Missing end tag"); } tag.EndTagPosition = endTagPosition; // Get all the text inbetween the start and end tags - that's the content int contentLength = tag.EndTagPosition.StartPosition - tag.StartTagPosition.EndPosition; tag.Contents = tag.SearchText.Substring(tag.StartTagPosition.EndPosition, contentLength); }