public void Apply(WordRange range, object source) { foreach (IReplacement replacement in Replacements) { replacement.Apply(range, source); } foreach (KeyValuePair <string, ReplacementsTree> entry in _subRanges) { string tagName = entry.Key; WordRange nextEntry = GetNextEntry(range, tagName); int index = 0; ReplacementsTree replacementsTree = entry.Value; IList <object> items = replacementsTree.GetItems(source); while (nextEntry != null) { if (items.Count == 0) { nextEntry.Replace(tagName, string.Empty); } else { if (index < items.Count) { if (index < items.Count - 1) { nextEntry.InsertAfter(nextEntry); } object item = items[index]; replacementsTree.Apply(nextEntry, item); AddBookmark(item, nextEntry); index++; if (index == items.Count) { index = 0; } } WordRange expandedRange = nextEntry.GetExpandedRange(0, 1); string expandedText = expandedRange.Text; if (!(expandedText.Length > nextEntry.Text.Length && expandedText[expandedText.Length - 1] == '\r')) { expandedRange = nextEntry; } string[] tags = tagName.Split('*'); for (int i = 0; i < tags.Length; i++) { DeleteTag(expandedRange, tags[i]); } } nextEntry = GetNextEntry(range, tagName); } } }
public PriceListGenerator(ReplacementsTree replacements) { _replacements = replacements; }
public void Add(string pattern, ReplacementsTree subTree) { _subRanges.Add(pattern, subTree); }