public ITextIterator BuildTextIterator(ProvidedDocumentInformation info)
 {
     Debug.Assert(info != null);
     return new ForwardTextIterator(info.TextBuffer, info.EndOffset);
 }
예제 #2
0
        public ISearchResult FindNext(SearchOptions options)
        {
            // insanity check
            Debug.Assert(searchStrategy      != null);
            Debug.Assert(documentIterator    != null);
            Debug.Assert(textIteratorBuilder != null);
            Debug.Assert(options             != null);

            if (info != null && textIterator != null && documentIterator.CurrentFileName != null) {
                if (info.FileName != documentIterator.CurrentFileName) { // create new iterator, if document changed
                    info         = documentIterator.Current;
                    textIterator = textIteratorBuilder.BuildTextIterator(info);
                } else { // old document -> initialize iterator position to caret pos
                    textIterator.Position = info.CurrentOffset;
                }

                ISearchResult result = CreateNamedSearchResult(searchStrategy.FindNext(textIterator, options));
                if (result != null) {
                    info.CurrentOffset = textIterator.Position;
                    return result;
                }
            }

            // not found or first start -> move forward to the next document
            if (documentIterator.MoveForward()) {
                info = documentIterator.Current;
                // document is valid for searching -> set iterator & fileName
                if (info != null && info.TextBuffer != null && info.EndOffset >= 0 && info.EndOffset < info.TextBuffer.Length) {
                    textIterator = textIteratorBuilder.BuildTextIterator(info);
                } else {
                    textIterator = null;
                }

                return FindNext(options);
            }
            return null;
        }