예제 #1
0
        public override TextIndexList SelectIndexes(string text)
        {
            TextIndexList indexes = new TextIndexList();

            if (OuterRegexString != "" && InnerRegexString != "")
            {
                try
                {
                    Regex orx = new Regex(OuterRegexString);
                    Regex irx = new Regex(InnerRegexString);

                    MatchCollection omc = orx.Matches(text);
                    foreach (Match om in omc)
                    {
                        if (om.Length > 0)
                        {
                            MatchCollection imc = irx.Matches(om.Value);
                            foreach (Match im in imc)
                            {
                                if (im.Length > 0)
                                {
                                    indexes.Add(new TextIndex(om.Index + im.Index, im.Length));
                                }
                            }
                        }
                    }
                }
                catch { }
            }

            return(indexes);
        }
예제 #2
0
        public override TextIndexList Ranges(string text)
        {
            TextIndexList ranges = new TextIndexList();

            TextIndex t = new TextIndex(Start, Length);

            ranges.Add(t);
            return(ranges);
        }
예제 #3
0
        public virtual List <string> SelectText(string text)
        {
            List <string> selected = new List <string>();
            TextIndexList tl       = SelectIndexes(text);

            foreach (TextIndex ti in tl)
            {
                selected.Add(text.Substring(ti.Start, ti.Length));
            }
            return(selected);
        }
예제 #4
0
        public virtual List <T> SelectList <T>(string text, Func <string, T> transformation)
        {
            List <T>      result = new List <T>();
            TextIndexList tl     = SelectIndexes(text);

            foreach (TextIndex t in tl)
            {
                result.Add(transformation(t.Text(text)));
            }

            return(result);
        }
예제 #5
0
        public virtual TextIndex SelectIndex(string text, Func <string, bool> test)
        {
            TextIndexList tl = SelectIndexes(text);

            foreach (TextIndex t in tl)
            {
                if (test(t.Text(text)))
                {
                    return(t);
                }
            }
            return(null);
        }
예제 #6
0
        public virtual TextIndex SelectIndex(string text, Func <int, bool> test)
        {
            TextIndexList tl = SelectIndexes(text);

            for (int i = 0; i < tl.Count;)
            {
                if (test(i))
                {
                    return(tl[i]);
                }
            }
            return(null);
        }
예제 #7
0
        public override TextIndexList SelectIndexes(string text)
        {
            StringReader  sr         = new StringReader(text);
            TextIndexList tl         = new TextIndexList();
            int           currentPos = 0;

            while (sr.Peek() != -1)
            {
                string line = sr.ReadLine();
                tl.Add(new TextIndex(currentPos, line.Length));
                currentPos += line.Length;
            }
            return(tl);
        }
예제 #8
0
        public override TextIndexList SelectIndexes(string text)
        {
            TextIndexList indexes = new TextIndexList();

            foreach (string word in mStrings)
            {
                int index = text.IndexOf(word, 0, StringComparison);
                while (index != -1)
                {
                    indexes.Add(new TextIndex(index, word.Length));
                    index = text.IndexOf(word, index + word.Length, StringComparison);
                }
            }
            return(indexes);
        }
예제 #9
0
        public virtual List <string> SelectText(string text, Func <string, bool> test, Func <string, string> transformation)
        {
            List <string> selected = new List <string>();
            TextIndexList tl       = SelectIndexes(text);

            foreach (TextIndex ti in tl)
            {
                string selectedText = ti.Text(text);
                if (test(selectedText))
                {
                    selected.Add(transformation(ti.Text(text)));
                }
            }
            return(selected);
        }
예제 #10
0
        public override TextIndexList SelectIndexes(string text)
        {
            TextIndexList indexes = new TextIndexList();

            foreach (string rString in mRegexStrings)
            {
                Regex           rx = new Regex(rString);
                MatchCollection mc = rx.Matches(text);
                foreach (Match m in mc)
                {
                    indexes.Add(new TextIndex(m.Index, m.Length));
                }
            }
            return(indexes);
        }
예제 #11
0
        public static PreparedDecorationCollection Merge(PreparedDecorationCollection previous, PreparedDecorationCollection current, TextDelta td)
        {
            if (previous.mDecorations.Count == 0)
            {
                current.mDifferenceRange = current.Bounds();
                return(current);
            }
            if (AreDecorationsSame(previous, current))
            {
                PreparedDecorationCollection merged = new PreparedDecorationCollection();
                TextIndexList differenceRanges      = new TextIndexList();
                for (int i = 0; i < previous.Count; i++)
                {
                    TextIndexList previousIndex   = previous.Index(i);
                    TextIndexList currentIndex    = current.Index(i);
                    TextIndex     differenceRange = currentIndex.RangeDifferentFrom(previousIndex);
                    if (differenceRange != null && differenceRange.Length > 0)
                    {
                        differenceRanges.Add(differenceRange);
                    }
                }
                differenceRanges.Add(td.TextIndex);

                merged.mDifferenceRange = differenceRanges.Bounds;
                TextIndex activeArea = differenceRanges.Bounds;
                if (activeArea != null)
                {
                    for (int i = 0; i < previous.Count; i++)
                    {
                        TextIndexList currentIndex = current.Index(i);
                        TextIndexList projected    = currentIndex.Projection(activeArea);

                        if (projected.IndexLengthUpperBound() > 0)// Are there and textindexes in projected that have a length > 0
                        {
                            merged.Add(current.Decoration(i), projected);
                        }
                    }
                }

                return(merged);
            }
            else
            {
                current.mAreDecorationsChanged = true;
                return(current);
            }
        }
예제 #12
0
        public override TextIndexList SelectIndexes(string Text)
        {
            TextIndexList indexes = new TextIndexList();

            if (RegexString != "" || RegexString != null)
            {
                if (RegexMatch == "" || RegexMatch == null)
                {
                    try
                    {
                        Regex           rx = new Regex(RegexString, mRegexOptions);
                        MatchCollection mc = rx.Matches(Text);
                        foreach (Match m in mc)
                        {
                            if (m.Length > 0)
                            {
                                indexes.Add(new TextIndex(m.Index, m.Length));
                            }
                        }
                    }
                    catch (Exception ex) {
                        Debug.WriteLine(ex.Message);
                    }
                }
                else
                {
                    try
                    {
                        Regex           rx = new Regex(RegexString, RegexOptions);
                        MatchCollection mc = rx.Matches(Text);
                        foreach (Match m in mc)
                        {
                            if (m.Length > 0)
                            {
                                indexes.Add(new TextIndex(m.Groups[RegexMatch].Index, m.Groups[RegexMatch].Length));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
            }
            return(indexes);
        }
예제 #13
0
        public TextIndex Bounds()
        {
            TextIndexList boundlist = new  TextIndexList();

            foreach (TextIndexList t in this.mIndexes)
            {
                if (t != null && t.Count > 0)
                {
                    boundlist.Add(t.Bounds);
                }
            }
            if (boundlist.Count > 0)
            {
                return(boundlist.Bounds);
            }
            else
            {
                return(null);
            }
        }
예제 #14
0
        public override TextIndexList SelectIndexes(string text)
        {
            TextIndexList pairs = new TextIndexList();

            foreach (string word in mWords)
            {
                string rstring = @"(?i:\b" + word + @"\b)";
                if (IsCaseSensitive)
                {
                    rstring = @"\b" + word + @"\b)";
                }
                Regex           rx = new Regex(rstring);
                MatchCollection mc = rx.Matches(text);
                foreach (Match m in mc)
                {
                    pairs.Add(new TextIndex(m.Index, m.Length));
                }
            }
            return(pairs);
        }
예제 #15
0
        private void ApplyDecoration(Decoration d, TextIndexList tl)
        {
            switch (d.DecorationType)
            {
            case EDecorationType.TextColor:
                foreach (TextIndex t in tl)
                {
                    this.Select(t.Start, t.Length);
                    this.SelectionColor = d.Color;
                }
                break;

            case EDecorationType.Hilight:
                foreach (TextIndex t in tl)
                {
                    this.Select(t.Start, t.Length);
                    this.SelectionBackColor = d.Color;
                }
                break;
            }
        }
예제 #16
0
        public virtual bool DoesTextIndexExist(string text)
        {
            TextIndexList tl = SelectIndexes(text);

            return(tl.Count > 0);
        }
예제 #17
0
        public virtual TextIndex SelectIndex(string text)
        {
            TextIndexList tl = SelectIndexes(text);

            return(tl[0]);
        }
예제 #18
0
        public virtual string Delete(string text)
        {
            TextIndexList tl = SelectIndexes(text);

            return(tl.Delete(text));
        }
예제 #19
0
 public void  Add(Decoration decoration, TextIndexList index)
 {
     mDecorations.Add(decoration);
     mIndexes.Add(index);
 }