public object GetAttributeValue(int attribute) { // Lazy load mappings if (attr_to_val_handler == null) { PopulateAttributeDictionary(); } if (!attr_to_val_handler.ContainsKey(attribute)) { throw new ArgumentException(); } TagDataValueHandler val_handler = attr_to_val_handler[attribute]; Line line; LineTag tag; int pos; List <TagData> tags = new List <TagData> (); Document d = textboxbase.document; int point = normalizer.StartPoint; while (point < normalizer.EndPoint) { d.CharIndexToLineTag(point, out line, out tag, out pos); tags.Add(new TagData(tag, line)); point += tag.Length; } IEnumerable <TagData> results = tags.Distinct(new LineTagComparer(val_handler)); int count = results.Count(); if (count == 1) { return(val_handler(results.First())); } else if (count > 1) { return(TextPattern.MixedAttributeValue); } return(null); }
public LineTagComparer(TagDataValueHandler h) { this.val_handler = h; }
public ITextRangeProvider FindAttribute(int attribute, object @value, bool backward) { // Lazy load mappings if (attr_to_val_handler == null) { PopulateAttributeDictionary(); } if (!attr_to_val_handler.ContainsKey(attribute)) { return(null); } Line line; LineTag tag; int pos; TagDataValueHandler val_handler = attr_to_val_handler[attribute]; Document d = textboxbase.document; TextRangeProvider range = null; if (!backward) { for (int i = StartPoint; i < EndPoint; i += tag.Length) { d.CharIndexToLineTag(i, out line, out tag, out pos); if (val_handler(new TagData(tag, line)).Equals(@value)) { if (range == null) { range = new TextRangeProvider(provider, textboxbase, i, i + tag.Length); } else { range.EndPoint += tag.Length; } } else if (range != null) { break; } } } else { for (int i = EndPoint - 1; i >= StartPoint; i -= tag.Length) { d.CharIndexToLineTag(i, out line, out tag, out pos); if (val_handler(new TagData(tag, line)).Equals(@value)) { if (range == null) { int start = i - tag.Length + 1; range = new TextRangeProvider(provider, textboxbase, start, start + tag.Length); } else { range.StartPoint -= tag.Length; } } else if (range != null) { break; } } } return(range); }