示例#1
0
        private string Parse(string input, IReadingStrategy readingStrategy)
        {
            reader = new Reader(readingStrategy);

            var result = new StringBuilder();
            while (!string.IsNullOrEmpty(input))
            {
                var tagResult = reader.Read(input);
                result.Append(tagResult.Text);
                if (tagResult.TagType == TagType.Open)
                {
                    if (tagResult.Tag.RequiresClosingTag)
                    {
                        stack.Push(tagResult);
                    }
                    result.Append(tagResult.OpeningTagValue);
                }
                else if (tagResult.TagType == TagType.Close)
                {
                    if (stack.Count > 0)
                    {
                        TagResult tagToBeClosed;
                        do
                        {
                            tagToBeClosed = stack.Pop();
                            result.Append(tagToBeClosed.ClosingTagValue);
                        } while (stack.Count > 0 && tagToBeClosed.Tag.BbTag != tagResult.Tag.BbTag);
                    }
                }
                input = tagResult.RemainingInput;
            }

            while (stack.Count > 0)
                result.Append(stack.Pop().ClosingTagValue);

            return result.ToString();
        }
示例#2
0
 public Reader(IReadingStrategy readingStrategy) => _readingStrategy = readingStrategy;
示例#3
0
 public Reader(IReadingStrategy readingStrategy)
 {
     this.readingStrategy = readingStrategy;
 }