예제 #1
0
        public static BetweenTagsResult GetBetweenTags(List <Token> tokens, string startTag, string endTag, int startIndex = 0)
        {
            BetweenTagsResult result = new BetweenTagsResult();

            result.StartIndex = startIndex;
            result.TokenList  = new List <Token>();

            int  depth        = 0;
            bool isStartFound = false;
            int  i;

            for (i = startIndex; i < tokens.Count; i++)
            {
                Token token = tokens[i];

                if (token.Type == TokenType.Symbol)
                {
                    if (isStartFound)
                    {
                        if (token.Text == startTag)
                        {
                            depth++;
                        }
                        else if (token.Text == endTag)
                        {
                            if (depth == 0)
                            {
                                i++;
                                result.Status = true;
                                break;
                            }

                            depth--;
                        }
                    }
                    else
                    {
                        if (token.Text == startTag)
                        {
                            isStartFound = true;
                            continue;
                        }
                    }
                }

                if (isStartFound)
                {
                    result.TokenList.Add(token);
                }
            }

            result.EndIndex = i;
            return(result);
        }
예제 #2
0
파일: Tokenizer.cs 프로젝트: KamilKZ/ShareX
        public static BetweenTagsResult GetBetweenTags(List<Token> tokens, string startTag, string endTag, int startIndex = 0)
        {
            BetweenTagsResult result = new BetweenTagsResult();
            result.StartIndex = startIndex;
            result.TokenList = new List<Token>();

            int depth = 0;
            bool isStartFound = false;
            int i;

            for (i = startIndex; i < tokens.Count; i++)
            {
                Token token = tokens[i];

                if (token.Type == TokenType.Symbol)
                {
                    if (isStartFound)
                    {
                        if (token.Text == startTag)
                        {
                            depth++;
                        }
                        else if (token.Text == endTag)
                        {
                            if (depth == 0)
                            {
                                i++;
                                result.Status = true;
                                break;
                            }

                            depth--;
                        }
                    }
                    else
                    {
                        if (token.Text == startTag)
                        {
                            isStartFound = true;
                            continue;
                        }
                    }
                }

                if (isStartFound)
                {
                    result.TokenList.Add(token);
                }
            }

            result.EndIndex = i;
            return result;
        }