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(); }
public Reader(IReadingStrategy readingStrategy) => _readingStrategy = readingStrategy;
public Reader(IReadingStrategy readingStrategy) { this.readingStrategy = readingStrategy; }