Пример #1
0
        private void GetAllWeSOFTags(ref string htmlText)
        {
            HtmlCommentTag temp     = null;
            int            startPos = 0;

            do
            {
                temp = GetNextHTMLWeSofTag(startPos, ref htmlText);
                if (temp != null)
                {
                    //Something has been found...
                    if (temp.isWesofTag == true)
                    {
                        //And this was a weSOF section
                        if (_TagsFound == null)
                        {
                            _TagsFound = new LinkedList <WesofHtmlTag>();
                        }

                        //Adding tag to the list
                        _TagsFound.AddLast((WesofHtmlTag)temp);

                        //Continue searching from the end position
                        if (((WesofHtmlTag)temp).closingTagEndIndex != null)
                        {
                            startPos = (int)((WesofHtmlTag)temp).closingTagEndIndex;
                        }
                        else
                        {
                            //A tag found without end... break out from the loop
                            if (Configuration.IsDebugModeOn)
                            {
                                _CLI.Out("Error. A WeSOF comment tag found without closing end. Breaking up searching of WeSOF tags.");
                            }
                            break;
                        }
                    }
                    else
                    {
                        //And this was just a general HTML tag.
                        //Continue searching after that.
                        if (temp.startTagendIndex != null)
                        {
                            startPos = (int)temp.startTagendIndex;
                        }
                        else
                        {
                            //A tag found without end... break out from the loop
                            if (Configuration.IsDebugModeOn)
                            {
                                _CLI.Out("Error. A html comment tag found without closing end. Breaking up searching of WeSOF tags.");
                            }
                            break;
                        }
                    }
                }
            } while (temp != null);
        }
Пример #2
0
        private HtmlCommentTag GetNextHTMLWeSofTag(int startPos, ref string htmlText)
        {
            WesofHtmlTag result = null;

            //Finds the next HTML comment start
            int start = FindHtmlCommentTag(startPos, true, ref htmlText);
            int end   = -1;

            //Finds the comment end
            if (start > -1)
            {
                end = FindHtmlCommentTag(start, false, ref htmlText);
            }


            //If tag found, checks if it is a WESOF start tag
            if (end > -1)
            {
                if (IsHtmlTagWeSofTag(ref htmlText, start, end, true))
                {
                    //It was a WeSOF start tag.
                    result                  = new WesofHtmlTag();
                    result.isWesofTag       = true;
                    result.startIndex       = start;
                    result.startTagendIndex = end;
                    result.startTagString   = htmlText.Substring(start, end - start);

                    //Search for the closing tag
                    int  closingStart;
                    int  closingEnd;
                    bool isWesofTagStop = false;

                    //Search closing tags
                    int searchForEndFrom = end;
                    do
                    {
                        //Find first opening html comment tag
                        closingStart = FindHtmlCommentTag(searchForEndFrom, true, ref htmlText);
                        if (closingStart > -1)
                        {
                            //Find the end of the comment tag
                            closingEnd = FindHtmlCommentTag(closingStart, false, ref htmlText);
                            if (closingEnd > -1)
                            {
                                //Check if this was WeSOF closing tag
                                isWesofTagStop = IsHtmlTagWeSofTag(ref htmlText, closingStart, closingEnd, false);

                                if (isWesofTagStop)
                                {
                                    result.closingTagStartIndex = closingStart;
                                    result.closingTagEndIndex   = closingEnd;
                                    result.fullTagString        = htmlText.Substring(start, closingEnd - start);
                                    result.contentBetweenTags   = htmlText.Substring(end, closingStart - end);

                                    return(result);
                                }
                                else
                                {
                                    //Start look for a new HTML tag from the last html comment end.
                                    searchForEndFrom = closingEnd;
                                }
                            }
                            else
                            {
                                //No closing end found for an html comment. That's unlikely.
                                if (Configuration.IsDebugModeOn)
                                {
                                    _CLI.Out("Error. Cannot find closing for an HTML comment. Maybe the HTML file is invalid.");
                                }
                                return(null);
                            }
                        }
                    } while (closingStart > -1 && !isWesofTagStop);


                    if (isWesofTagStop)
                    {
                        return(result);
                    }
                }
                else
                {
                    //The found tag was a HTML comment, but not a WeSOF tag.
                    HtmlCommentTag commentFoundOnly = new HtmlCommentTag();
                    commentFoundOnly.isWesofTag       = false;
                    commentFoundOnly.startIndex       = start;
                    commentFoundOnly.startTagendIndex = end;
                    return(commentFoundOnly);
                }
            }

            return(null);
        }