Beispiel #1
0
        public bool Compare(ITextRangeProvider range)
        {
            TextRangeProvider rangeProvider = range as TextRangeProvider;

            if (rangeProvider == null)
            {
                return(false);
            }

            if (rangeProvider.TextProvider != provider)
            {
                throw new ArgumentException();
            }

            return((rangeProvider.StartPoint == StartPoint) &&
                   (rangeProvider.EndPoint == EndPoint));
        }
Beispiel #2
0
        public void MoveEndpointByRange(TextPatternRangeEndpoint endpoint,
                                        ITextRangeProvider targetRange,
                                        TextPatternRangeEndpoint targetEndpoint)
        {
            TextRangeProvider prov = (TextRangeProvider)targetRange;

            int val = (targetEndpoint == TextPatternRangeEndpoint.Start)
                                        ? prov.StartPoint : prov.EndPoint;

            if (endpoint == TextPatternRangeEndpoint.Start)
            {
                normalizer.StartPoint = val;
            }
            else if (endpoint == TextPatternRangeEndpoint.End)
            {
                normalizer.EndPoint = val;
            }
        }
Beispiel #3
0
        public int CompareEndpoints(TextPatternRangeEndpoint endpoint,
                                    ITextRangeProvider targetRange,
                                    TextPatternRangeEndpoint targetEndpoint)
        {
            TextRangeProvider targetRangeProvider = targetRange as TextRangeProvider;

            if (targetRangeProvider == null)
            {
                throw new ArgumentNullException();
            }

            if (targetRangeProvider.TextProvider != provider)
            {
                throw new ArgumentException();
            }

            int point      = endpoint == TextPatternRangeEndpoint.End ? EndPoint : StartPoint;
            int targePoint = (targetEndpoint == TextPatternRangeEndpoint.End)
                                ? targetRangeProvider.EndPoint : targetRangeProvider.StartPoint;

            return(point.CompareTo(targePoint));
        }
Beispiel #4
0
        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);
        }