Esempio n. 1
0
        public int Find(string pattern, int startAt, FastFindMode mode, bool matchCase,
                        FastFindDirection direction = FastFindDirection.Forward)
        {
            if (mode == FastFindMode.Contains)
            {
                StringComparison SC = matchCase ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
                int index           = -1;

                if (direction == FastFindDirection.Forward)
                {
                    index = Text.IndexOf(pattern, startAt, SC);
                }
                else
                {
                    index = Text.LastIndexOf(pattern, startAt, SC);
                }

                if (index != -1)
                {
                    SelectionStart  = index;
                    SelectionLength = pattern.Length;
                    return(index);
                }
            }
            else
            {
                RegexOptions options = matchCase ? RegexOptions.None : RegexOptions.IgnoreCase;
                Match        match   = Regex.Match(Text, pattern, options);

                if (match.Success)
                {
                    SelectionStart  = match.Index;
                    SelectionLength = match.Length;
                    return(match.Index);
                }
            }

            return(-1);
        }
Esempio n. 2
0
        public bool FindNext(string pattern, FastFindMode mode, bool matchCase,
                             FastFindDirection direction = FastFindDirection.Forward)
        {
            if (pattern.Length == 0 || HasText == false)
            {
                return(false);
            }
            int pos;

            if (lastFindPos > -1 && lastFindPattern == pattern)
            {
                int start = (lastFindPos + 1 > Text.Length) ? 0 : lastFindPos + 1;
                pos = Find(pattern, start, mode, matchCase, direction);
            }
            else
            {
                pos = Find(pattern, 0, mode, matchCase, direction);
            }

            lastFindPos     = (pos < 0) ? 0 : pos;
            lastFindPattern = pattern;
            return(pos != -1);
        }