public void SetUp() { // Set up SearchOptions required by the BruteForceSearchStrategy. SearchOptions.CurrentFindPattern = "foo"; SearchOptions.MatchCase = false; SearchOptions.MatchWholeWord = false; // Create search. search = new Search(); search.TextIteratorBuilder = new ForwardTextIteratorBuilder(); search.SearchStrategy = new BruteForceSearchStrategy(); MockCurrentDocumentIterator currentDocIterator = new MockCurrentDocumentIterator(); search.DocumentIterator = currentDocIterator; // Create the document to be searched. MockDocument doc = new MockDocument(); StringTextBufferStrategy textBufferStrategy = new StringTextBufferStrategy(); textBufferStrategy.SetContent("foo"); doc.TextBufferStrategy = textBufferStrategy; // Create a doc info with an initial end offset right // at the end of the text. ProvidedDocumentInformation docInfo = new ProvidedDocumentInformation(doc, @"C:\Temp\test.txt", doc.TextLength); currentDocIterator.Current = docInfo; currentDocIterator.CurrentFileName = docInfo.FileName; // Search the document. search.SearchStrategy.CompilePattern(null); result = search.FindNext(null); }
public ForwardTextIterator(ProvidedDocumentInformation info) { Debug.Assert(info != null); this.info = info; this.textBuffer = info.TextBuffer; this.position = info.CurrentOffset; this.endOffset = info.EndOffset; Reset(); }
public SearchResultMatch FindNext(IProgressMonitor monitor) { // insanity check Debug.Assert(searchStrategy != null); Debug.Assert(documentIterator != null); Debug.Assert(textIteratorBuilder != null); if (monitor != null && monitor.CancellationToken.IsCancellationRequested) { return(null); } if (info != null && textIterator != null && documentIterator.CurrentFileName != null) { ProvidedDocumentInformation currentInfo = documentIterator.Current; if (currentInfo != null) { if (!info.Equals(currentInfo)) // create new iterator, if document changed { info = currentInfo; textIterator = textIteratorBuilder.BuildTextIterator(info); } else // old document -> initialize iterator position to caret pos { textIterator.Position = info.CurrentOffset; } SearchResultMatch result = CreateNamedSearchResult(searchStrategy.FindNext(textIterator)); 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.EndOffset >= 0 && info.EndOffset <= info.Document.TextLength) { textIterator = textIteratorBuilder.BuildTextIterator(info); } else { textIterator = null; } return(FindNext(monitor)); } return(null); }
public override bool Equals(object obj) { ProvidedDocumentInformation info = obj as ProvidedDocumentInformation; if (info == null) { return(false); } return(this.fileName == info.fileName && this.textAreaControl == info.textAreaControl); }
public ForwardTextIterator(ProvidedDocumentInformation info) { if (info == null) throw new ArgumentNullException("info"); this.info = info; this.textBuffer = info.TextBuffer; this.position = info.CurrentOffset; this.endOffset = info.EndOffset; Reset(); }
public void SetUp() { // Create the document to be iterated through. MockDocument doc = new MockDocument(); StringTextBufferStrategy textBufferStrategy = new StringTextBufferStrategy(); doc.TextBufferStrategy = textBufferStrategy; ProvidedDocumentInformation docInfo = new ProvidedDocumentInformation(doc, @"C:\Temp\test.txt", 0); // Create the forward iterator. forwardTextIterator = new ForwardTextIterator(docInfo); }
public ForwardTextIterator(ProvidedDocumentInformation info) { if (info == null) { throw new ArgumentNullException("info"); } this.info = info; this.document = info.Document; this.position = info.CurrentOffset; this.endOffset = info.EndOffset; Reset(); }
public void SetUp() { // Create the document to be iterated through. MockDocument doc = new MockDocument(); StringTextBufferStrategy textBufferStrategy = new StringTextBufferStrategy(); textBufferStrategy.SetContent("bar"); doc.TextBufferStrategy = textBufferStrategy; // Create a doc info with an initial end offset right // at the end of the text. ProvidedDocumentInformation docInfo = new ProvidedDocumentInformation(doc, @"C:\Temp\test.txt", doc.TextLength); // Create the forward iterator. forwardTextIterator = new ForwardTextIterator(docInfo); }
public SearchResult FindNext() { // insanity check Debug.Assert(searchStrategy != null); Debug.Assert(documentIterator != null); Debug.Assert(textIteratorBuilder != 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; } SearchResult result = CreateNamedSearchResult(searchStrategy.FindNext(textIterator)); 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()); } return(null); }
public SearchResultMatch FindNext(int offset, int length) { if (info != null && textIterator != null && documentIterator.CurrentFileName != null) { ProvidedDocumentInformation currentInfo = documentIterator.Current; if (currentInfo != null) { if (!info.Equals(currentInfo)) // create new iterator, if document changed { info = currentInfo; textIterator = textIteratorBuilder.BuildTextIterator(info); } else // old document -> initialize iterator position to caret pos { textIterator.Position = info.CurrentOffset; } SearchResultMatch result = CreateNamedSearchResult(searchStrategy.FindNext(textIterator, offset, length)); 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.EndOffset >= 0 && info.EndOffset <= info.Document.TextLength) { textIterator = textIteratorBuilder.BuildTextIterator(info); } else { textIterator = null; } return(FindNext(offset, length)); } return(null); }
public ITextIterator BuildTextIterator(ProvidedDocumentInformation info) { Debug.Assert(info != null); return new ForwardTextIterator(info); }
public ITextIterator BuildTextIterator(ProvidedDocumentInformation info) { Debug.Assert(info != null); return(new ForwardTextIterator(info)); }
public SearchResult FindNext() { // insanity check Debug.Assert(searchStrategy != null); Debug.Assert(documentIterator != null); Debug.Assert(textIteratorBuilder != 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; } SearchResult result = CreateNamedSearchResult(searchStrategy.FindNext(textIterator)); 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(); } return null; }
public SearchResultMatch FindNext(int offset, int length) { if (info != null && textIterator != null && documentIterator.CurrentFileName != null) { ProvidedDocumentInformation currentInfo = documentIterator.Current; if (currentInfo != null) { if (!info.Equals(currentInfo)) { // create new iterator, if document changed info = currentInfo; textIterator = textIteratorBuilder.BuildTextIterator(info); } else { // old document -> initialize iterator position to caret pos textIterator.Position = info.CurrentOffset; } SearchResultMatch result = CreateNamedSearchResult(searchStrategy.FindNext(textIterator, offset, length)); 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(offset, length); } return null; }