int InternalFindNext(ITextIterator textIterator, SearchOptions options)
 {
     int j = 0;
     if (!textIterator.MoveAhead(1)) {
         return -1;
     }
     while (true) { // until pattern found or Iterator finished
         while (j >= 0 && searchPattern[j] != (options.IgnoreCase ? Char.ToUpper(textIterator.GetCharRelative(j)) : textIterator.GetCharRelative(j))) {
             if (!textIterator.MoveAhead(j - overlap[j])) {
                 return -1;
             }
             j = overlap[j];
         }
         if (++j >= searchPattern.Length) {
             if ((!options.SearchWholeWordOnly || SearchReplaceUtilities.IsWholeWordAt(textIterator, searchPattern.Length))) {
                 return textIterator.Position;
             }
             if (!textIterator.MoveAhead(j - overlap[j])) {
                 return -1;
             }
             j = overlap[j];
         }
     }
 }
        public ISearchResult FindNext(ITextIterator textIterator, SearchOptions options, bool reverseSearch)
        {
            if (reverseSearch)
                throw new NotSupportedException ();

            int pos = textIterator.Position;

            int offset = InternalFindNext(textIterator, options);
            if (offset == -1) return null;

            if (textIterator.GetCharRelative (searchPattern.Length) == char.MinValue) {
                if (pos != offset)
                    return FindNext(textIterator, options, false);
                else
                    return null;
            }

            return new DefaultSearchResult (textIterator, searchPattern.Length);
        }