public SearchResultMatch FindNext(ITextIterator textIterator, int offset, int length)
		{
			string document = textIterator.TextBuffer.GetText(0, textIterator.TextBuffer.Length);
			
			while (textIterator.MoveAhead(1) && TextSelection.IsInsideRange(textIterator.Position, offset, length)) {
				Match m = regex.Match(document, textIterator.Position);
				if (m == null || !m.Success) {
					while (textIterator.Position < document.Length - 1) {
						if (!textIterator.MoveAhead(1))
							return null;
					}
				} else {
					int delta = m.Index - textIterator.Position;
					if (delta <= 0 || textIterator.MoveAhead(delta)) {
						if (TextSelection.IsInsideRange(m.Index + m.Length - 1, offset, length)) {
							return new RegexSearchResult(m);
						} else {
							return null;
						}
					} else {
						return null;
					}
				}
			}
			
			return null;
		}
示例#2
0
        /// <summary>
        /// Determines number of line breaks before position
        /// </summary>
        public static int LineBreaksBeforePosition(ITextIterator iterator, int position) {
            int count = 0;

            if (position > 0) {
                for (int i = position - 1; i >= 0; i--) {
                    char ch = iterator[i];

                    if (!Char.IsWhiteSpace(ch))
                        return count;

                    if (ch == '\r') {
                        count++;
                        if (i > 0 && iterator[i - 1] == '\n') {
                            i--;
                        }
                    } else if (ch == '\n') {
                        count++;
                        if (i > 0 && iterator[i - 1] == '\r') {
                            i--;
                        }
                    }
                }
            }

            return count;
        }
示例#3
0
        public SearchResult FindNext(ITextIterator textIterator, int offset, int length)
        {
            string document = textIterator.TextBuffer.GetText(0, textIterator.TextBuffer.Length);

            while (textIterator.MoveAhead(1) && TextSelection.IsInsideRange(textIterator.Position, offset, length))
            {
                Match m = regex.Match(document, textIterator.Position);
                if (m == null || m.Index <= 0 || m.Length <= 0)
                {
                }
                else
                {
                    int delta = m.Index - textIterator.Position;
                    if (delta <= 0 || textIterator.MoveAhead(delta))
                    {
                        if (TextSelection.IsInsideRange(m.Index + m.Length - 1, offset, length))
                        {
                            return(new RegexSearchResult(m));
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            return(null);
        }
示例#4
0
        /// <summary>
        /// Determines number of line breaks after position
        /// </summary>
        public static int LineBreaksAfterPosition(ITextIterator iterator, int position)
        {
            int count = 0;

            for (int i = position; i < iterator.Length; i++)
            {
                char ch = iterator[i];

                if (!Char.IsWhiteSpace(ch))
                {
                    return(count);
                }

                if (ch == '\r')
                {
                    count++;
                    if (i < iterator.Length - 1 && iterator[i + 1] == '\n')
                    {
                        i++;
                    }
                }
                else if (ch == '\n')
                {
                    count++;
                    if (i < iterator.Length - 1 && iterator[i + 1] == '\r')
                    {
                        i++;
                    }
                }
            }
            return(count);
        }
 int InternalFindNext(ITextIterator textIterator, int offset, int length)
 {
     while (textIterator.MoveAhead(1))
     {
         if (textIterator.Position >= offset + length)
         {
             textIterator.Position = offset;
         }
         if (SearchOptions.MatchCase ? MatchCaseSensitive(textIterator.Document, textIterator.Position, searchPattern) : MatchCaseInsensitive(textIterator.Document, textIterator.Position, searchPattern))
         {
             if (!SearchOptions.MatchWholeWord || IsWholeWordAt(textIterator.Document, textIterator.Position, searchPattern.Length))
             {
                 if (TextSelection.IsInsideRange(textIterator.Position + searchPattern.Length - 1, offset, length))
                 {
                     return(textIterator.Position);
                 }
                 else
                 {
                     return(-1);
                 }
             }
         }
     }
     return(-1);
 }
示例#6
0
        public SearchResultMatch FindNext(ITextIterator textIterator)
        {
            string document = textIterator.TextBuffer.GetText(0, textIterator.TextBuffer.Length);

            while (textIterator.MoveAhead(1))
            {
                Match m = regex.Match(document, textIterator.Position);
                if (m == null || !m.Success)
                {
                    while (textIterator.Position < document.Length - 1)
                    {
                        if (!textIterator.MoveAhead(1))
                        {
                            return(null);
                        }
                    }
                }
                else
                {
                    int delta = m.Index - textIterator.Position;
                    if (delta <= 0 || textIterator.MoveAhead(delta))
                    {
                        return(new RegexSearchResult(m));
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            return(null);
        }
示例#7
0
 int InternalFindNext(ITextIterator textIterator, int offset, int length)
 {
     while (textIterator.MoveAhead(1))
     {
         if (textIterator.Position >= offset + length)
         {
             textIterator.Position = offset;
         }
         int position = textIterator.Position;
         if (Match(textIterator.Document, position, !SearchOptions.MatchCase, 0))
         {
             if (!SearchOptions.MatchWholeWord || SearchReplaceUtilities.IsWholeWordAt(textIterator.Document, position, curMatchEndOffset - position))
             {
                 if (TextSelection.IsInsideRange(curMatchEndOffset - 1, offset, length))
                 {
                     textIterator.MoveAhead(curMatchEndOffset - position - 1);
                     return(position);
                 }
                 else
                 {
                     return(-1);
                 }
             }
         }
     }
     return(-1);
 }
        public ISearchResult FindNext(ITextIterator textIterator, SearchOptions options, bool reverseSearch)
        {
            if (reverseSearch)
                throw new NotSupportedException ();

            int charCount = InternalFindNext(textIterator, options);
            return charCount != -1 ? new DefaultSearchResult (textIterator, charCount) : null;
        }
 public DefaultSearchResult(ITextIterator iter, int length)
 {
     position = iter.Position;
     offset = iter.DocumentOffset;
     line = iter.Line + 1;
     column = iter.Column + 1;
     this.length = length;
     documentInformation = iter.DocumentInformation;
 }
示例#10
0
        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);
        }
		int InternalFindNext(ITextIterator textIterator)
		{
			while (textIterator.MoveAhead(1)) {
				if (SearchOptions.MatchCase ? MatchCaseSensitive(textIterator.Document, textIterator.Position, searchPattern) : MatchCaseInsensitive(textIterator.Document, textIterator.Position, searchPattern)) {
					if (!SearchOptions.MatchWholeWord || IsWholeWordAt(textIterator.Document, textIterator.Position, searchPattern.Length)) {
						return textIterator.Position;
					}
				}
			}
			return -1;
		}
示例#12
0
        public int CopyPrecedingLineBreaks(ITextIterator iterator, int position) {
            int lineBreakCount = Whitespace.LineBreaksBeforePosition(iterator, position);
            int recentlyAddedCount = RecentlyAddedLineBreakCount();
            int breaks = lineBreakCount - recentlyAddedCount;

            for (int i = 0; i < breaks; i++) {
                HardLineBreak();
            }

            return breaks;
        }
示例#13
0
        int InternalFindNext(ITextIterator textIterator)
        {
//			while (textIterator.MoveAhead(1)) {
//				if (SearchOptions.MatchCase ? MatchCaseSensitive(textIterator.TextBuffer, textIterator.Position, searchPattern) : MatchCaseInsensitive(textIterator.TextBuffer, textIterator.Position, searchPattern)) {
//					if (!SearchOptions.MatchWholeWord || IsWholeWordAt(textIterator.TextBuffer, textIterator.Position, searchPattern.Length)) {
//						return textIterator.Position;
//					}
//				}
//			}
            return(-1);
        }
示例#14
0
        public int CopyFollowingLineBreaks(ITextIterator iterator, int position)
        {
            var lineBreakCount     = Whitespace.LineBreaksAfterPosition(iterator, position);
            var recentlyAddedCount = RecentlyAddedLineBreakCount();
            var breaks             = lineBreakCount - recentlyAddedCount;

            for (var i = 0; i < breaks; i++)
            {
                HardLineBreak();
            }

            return(breaks);
        }
示例#15
0
        public int CopyPrecedingLineBreaks(ITextIterator iterator, int position)
        {
            int lineBreakCount     = Whitespace.LineBreaksBeforePosition(iterator, position);
            int recentlyAddedCount = RecentlyAddedLineBreakCount();
            int breaks             = lineBreakCount - recentlyAddedCount;

            for (int i = 0; i < breaks; i++)
            {
                HardLineBreak();
            }

            return(breaks);
        }
 int InternalFindNext(ITextIterator textIterator)
 {
     while (textIterator.MoveAhead(1))
     {
         if (SearchOptions.MatchCase ? MatchCaseSensitive(textIterator.Document, textIterator.Position, searchPattern) : MatchCaseInsensitive(textIterator.Document, textIterator.Position, searchPattern))
         {
             if (!SearchOptions.MatchWholeWord || IsWholeWordAt(textIterator.Document, textIterator.Position, searchPattern.Length))
             {
                 return(textIterator.Position);
             }
         }
     }
     return(-1);
 }
示例#17
0
        /// <summary>
        /// Determines if there is only whitespace and a line break before position
        /// </summary>
        public static bool IsNewLineBeforePosition(ITextIterator iterator, int position) {
            if (position > 0) {
                for (int i = position - 1; i >= 0; i--) {
                    char ch = iterator[i];

                    if (!Char.IsWhiteSpace(ch))
                        return false;

                    if (ch.IsLineBreak())
                        return true;
                }
            }

            return false;
        }
		int InternalFindNext(ITextIterator textIterator, int offset, int length)
		{
			while (textIterator.MoveAhead(1) && TextSelection.IsInsideRange(textIterator.Position, offset, length)) {
				if (SearchOptions.MatchCase ? MatchCaseSensitive(textIterator.Document, textIterator.Position, searchPattern) : MatchCaseInsensitive(textIterator.Document, textIterator.Position, searchPattern)) {
					if (!SearchOptions.MatchWholeWord || IsWholeWordAt(textIterator.Document, textIterator.Position, searchPattern.Length)) {
						if (TextSelection.IsInsideRange(textIterator.Position + searchPattern.Length - 1, offset, length)) {
							return textIterator.Position;
						} else {
							return -1;
						}
					}
				}
			}
			return -1;
		}
 int InternalFindNext(ITextIterator textIterator)
 {
     while (textIterator.MoveAhead(1))
     {
         int position = textIterator.Position;
         if (Match(textIterator.TextBuffer, position, !SearchOptions.MatchCase, 0))
         {
             if (!SearchOptions.MatchWholeWord || SearchReplaceUtilities.IsWholeWordAt(textIterator.TextBuffer, position, curMatchEndOffset - position))
             {
                 textIterator.MoveAhead(curMatchEndOffset - position - 1);
                 return(position);
             }
         }
     }
     return(-1);
 }
示例#20
0
 private static bool HasLineTextBeforePosition(ITextIterator tp, int position, out int lineBreakIndex)
 {
     lineBreakIndex = 0;
     for (var i = position - 1; i >= 0; i--)
     {
         if (tp[i].IsLineBreak())
         {
             lineBreakIndex = i;
             break;
         }
         if (!char.IsWhiteSpace(tp[i]))
         {
             return(true);
         }
     }
     return(false);
 }
示例#21
0
        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);
        }
示例#22
0
        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);
        }
示例#23
0
        public SearchResultMatch FindNext(ITextIterator textIterator, int offset, int length)
        {
            string document = textIterator.Document.GetText(0, textIterator.Document.TextLength);

            while (textIterator.MoveAhead(1))
            {
                if (textIterator.Position >= offset + length)
                {
                    textIterator.Position = offset;
                }
                Match m = regex.Match(document, textIterator.Position);
                if (m == null || !m.Success)
                {
                    while (textIterator.Position < document.Length - 1)
                    {
                        if (!textIterator.MoveAhead(1))
                        {
                            return(null);
                        }
                    }
                }
                else
                {
                    int delta = m.Index - textIterator.Position;
                    if (delta <= 0 || textIterator.MoveAhead(delta))
                    {
                        if (TextSelection.IsInsideRange(m.Index + m.Length - 1, offset, length))
                        {
                            return(new RegexSearchResult(m));
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            return(null);
        }
        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);
        }
		public SearchResult FindNext(ITextIterator textIterator)
		{
			string document = textIterator.TextBuffer.GetText(0, textIterator.TextBuffer.Length);
			
			while (textIterator.MoveAhead(1)) {
				Match m = regex.Match(document, textIterator.Position);
				if (m == null || m.Index <= 0 || m.Length <= 0) {
					
				} else {
					int delta = m.Index - textIterator.Position;
					if (delta <= 0 || textIterator.MoveAhead(delta)) {
						return new RegexSearchResult(m);
					} else {
						return null;
					}
				}
			}
			
			return null;
		}
示例#26
0
        /// <summary>
        /// Determines if there is only whitespace and a line break before position
        /// </summary>
        public static bool IsNewLineBeforePosition(ITextIterator iterator, int position)
        {
            if (position > 0)
            {
                for (int i = position - 1; i >= 0; i--)
                {
                    char ch = iterator[i];

                    if (!Char.IsWhiteSpace(ch))
                    {
                        return(false);
                    }

                    if (ch.IsLineBreak())
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public ISearchResult FindNext(ITextIterator textIterator, SearchOptions options, bool reverseSearch)
        {
            if (reverseSearch)
                throw new NotSupportedException ();

            if (!textIterator.MoveAhead(1)) return null;
            if (regex == null) return null;

            int pos = textIterator.Position;
            string document = textIterator.ReadToEnd ();
            textIterator.Position = pos;

            Match m = regex.Match (document, 0);
            if (m == null || m.Index <= 0 || m.Length <= 0) {
                return null;
            } else {
                if (textIterator.MoveAhead (m.Index)) {
                    return new DefaultSearchResult (textIterator, m.Length);
                } else {
                    return null;
                }
            }
        }
示例#28
0
		public SearchResultMatch FindNext(ITextIterator textIterator)
		{
			string document = textIterator.Document.Text;
			
			while (textIterator.MoveAhead(1)) {
				Match m = regex.Match(document, textIterator.Position);
				if (m == null || !m.Success) {
					while (textIterator.Position < document.Length - 1) {
						if (!textIterator.MoveAhead(1))
							return null;
					}
				} else {
					int delta = m.Index - textIterator.Position;
					if (delta <= 0 || textIterator.MoveAhead(delta)) {
						return new RegexSearchResult(m);
					} else {
						return null;
					}
				}
			}
			
			return null;
		}
示例#29
0
        /// <summary>
        /// Determines number of line breaks after position
        /// </summary>
        public static int LineBreaksAfterPosition(ITextIterator iterator, int position) {
            int count = 0;

            for (int i = position; i < iterator.Length; i++) {
                char ch = iterator[i];

                if (!Char.IsWhiteSpace(ch))
                    return count;

                if (ch == '\r') {
                    count++;
                    if (i < iterator.Length - 1 && iterator[i + 1] == '\n') {
                        i++;
                    }
                } else if (ch == '\n') {
                    count++;
                    if (i < iterator.Length - 1 && iterator[i + 1] == '\r') {
                        i++;
                    }
                }
            }
            return count;
        }
示例#30
0
        /// <summary>
        /// Determines number of line breaks before position
        /// </summary>
        public static int LineBreaksBeforePosition(ITextIterator iterator, int position)
        {
            int count = 0;

            if (position > 0)
            {
                for (int i = position - 1; i >= 0; i--)
                {
                    char ch = iterator[i];

                    if (!Char.IsWhiteSpace(ch))
                    {
                        return(count);
                    }

                    if (ch == '\r')
                    {
                        count++;
                        if (i > 0 && iterator[i - 1] == '\n')
                        {
                            i--;
                        }
                    }
                    else if (ch == '\n')
                    {
                        count++;
                        if (i > 0 && iterator[i - 1] == '\r')
                        {
                            i--;
                        }
                    }
                }
            }

            return(count);
        }
 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 (textIterator.SupportsSearch (options, reverseSearch)) {
				if (textIterator.SearchNext (searchPattern, options, reverseSearch)) {
					DefaultSearchResult sr = new DefaultSearchResult (textIterator, searchPattern.Length);
					if (!reverseSearch)
						textIterator.MoveAhead (searchPattern.Length);
					return sr;
				} else
					return null;
			}
			
			if (reverseSearch)
				throw new NotSupportedException ();
				
			int offset = InternalFindNext(textIterator, options);
			if (offset >= 0) {
				int pos = textIterator.Position;
				textIterator.Position = offset;
				DefaultSearchResult sr = new DefaultSearchResult (textIterator, searchPattern.Length);
				textIterator.Position = pos;
				return sr;
			} else
				return null;
		}
        public SearchResult FindNext(ITextIterator textIterator)
        {
            int offset = InternalFindNext(textIterator);

            return(GetSearchResult(offset));
        }
示例#34
0
		public void Reset()
		{
			documentIterator.Reset();
			textIterator = null;
		}
示例#35
0
        /// <remarks>
        /// The find next method should search the next occurrence of the
        /// compiled pattern in the text using the textIterator and options.
        /// </remarks>
        public SearchResultMatch FindNext(ITextIterator textIterator)
        {
            int offset = InternalFindNext(textIterator);

            return(offset >= 0 ? new SearchResultMatch(offset, searchPattern.Length) : null);
        }
示例#36
0
		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;
		}
示例#37
0
		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 bool SupportsReverseSearch(ITextIterator textIterator, SearchOptions options)
 {
     return false;
 }
示例#39
0
 public SearchResultMatch FindNext(ITextIterator textIterator)
 {
     int offset = InternalFindNext(textIterator);
     return GetSearchResult(offset);
 }
示例#40
0
 int InternalFindNext(ITextIterator textIterator)
 {
     while (textIterator.MoveAhead(1)) {
         int position = textIterator.Position;
         if (Match(textIterator.TextBuffer, position, !SearchOptions.MatchCase, 0)) {
             if (!SearchOptions.MatchWholeWord || SearchReplaceUtilities.IsWholeWordAt(textIterator.TextBuffer, position, curMatchEndOffset - position)) {
                 textIterator.MoveAhead(curMatchEndOffset - position - 1);
                 return position;
             }
         }
     }
     return -1;
 }
 public void Reset()
 {
     documentIterator.Reset();
     textIterator = null;
     reverseSearchMap = null;
     cancelled = false;
     searchedFiles = 0;
     matches = 0;
     lastResultPos = -1;
 }
示例#42
0
 /// <remarks>
 /// The find next method should search the next occurrence of the 
 /// compiled pattern in the text using the textIterator and options.
 /// </remarks>
 public SearchResultMatch FindNext(ITextIterator textIterator)
 {
     int offset = InternalFindNext(textIterator);
     return offset >= 0 ? new SearchResultMatch(offset, searchPattern.Length) : null;
 }
示例#43
0
        /// <summary>
        /// Determines if there is a whitespace before given position
        /// </summary>
        public static bool IsWhitespaceBeforePosition(ITextIterator iterator, int position)
        {
            char charBefore = position > 0 ? iterator[position - 1] : 'x';

            return(Char.IsWhiteSpace(charBefore));
        }
        public void Build(ISearchStrategy strategy, ITextIterator it, SearchOptions options)
        {
            int startPos = it.Position;
            it.Reset ();

            ISearchResult res = strategy.FindNext (it, options, false);
            while (res != null) {
                matches.Add (res);
                res = strategy.FindNext (it, options, false);
            }
            it.Position = startPos;
        }
        public SearchResult FindNext(ITextIterator textIterator, int offset, int length)
        {
            int foundOffset = InternalFindNext(textIterator, offset, length);

            return(GetSearchResult(foundOffset));
        }
示例#46
0
		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 ISearchResult Find(SearchOptions options, bool reverse)
        {
            // insanity check
            Debug.Assert(searchStrategy      != null);
            Debug.Assert(documentIterator    != null);
            Debug.Assert(options             != null);

            while (!cancelled)
            {
                if (info != null && textIterator != null && documentIterator.CurrentFileName != null) {
                    if (info.FileName != documentIterator.CurrentFileName || lastWasReverse != reverse) {
                        // create new iterator, if document changed or search direction has changed.
                        info = documentIterator.Current;
                        textIterator = info.GetTextIterator ();
                        reverseSearchMap = null;
                        lastResultPos = -1;
                        if (reverse)
                            textIterator.MoveToEnd ();
                    }

                    ISearchResult result;
                    if (!reverse)
                        result = searchStrategy.FindNext (textIterator, options, false);
                    else {
                        if (searchStrategy.SupportsReverseSearch (textIterator, options)) {
                            result = searchStrategy.FindNext (textIterator, options, true);
                        }
                        else {
                            if (reverseSearchMap == null) {
                                reverseSearchMap = new SearchMap ();
                                reverseSearchMap.Build (searchStrategy, textIterator, options);
                            }
                            if (lastResultPos == -1)
                                lastResultPos = textIterator.Position;
                            result = reverseSearchMap.GetPreviousMatch (lastResultPos);
                            if (result != null)
                                textIterator.Position = result.Position;
                        }
                    }

                    if (result != null) {
                        matches++;
                        lastResultPos = result.Position;
                        lastWasReverse = reverse;
                        return result;
                    }
                }

                if (textIterator != null) textIterator.Close ();

                // not found or first start -> move forward to the next document
                bool more = !reverse ? documentIterator.MoveForward () : documentIterator.MoveBackward ();
                if (more) {
                    searchedFiles++;
                    info = documentIterator.Current;
                    textIterator = info.GetTextIterator ();
                    reverseSearchMap = null;
                    lastResultPos = -1;
                    if (reverse)
                        textIterator.MoveToEnd ();
                }
                else
                    cancelled = true;

                lastWasReverse = reverse;
            }

            cancelled = false;
            return null;
        }
示例#48
0
 public void Reset()
 {
     documentIterator.Reset();
     textIterator = null;
 }
示例#49
0
 int InternalFindNext(ITextIterator textIterator, int offset, int length)
 {
     while (textIterator.MoveAhead(1) && TextSelection.IsInsideRange(textIterator.Position, offset, length)) {
         int position = textIterator.Position;
         if (Match(textIterator.TextBuffer, position, !SearchOptions.MatchCase, 0)) {
             if (!SearchOptions.MatchWholeWord || SearchReplaceUtilities.IsWholeWordAt(textIterator.TextBuffer, position, curMatchEndOffset - position)) {
                 if (TextSelection.IsInsideRange(curMatchEndOffset - 1, offset, length)) {
                     textIterator.MoveAhead(curMatchEndOffset - position - 1);
                     return position;
                 } else {
                     return -1;
                 }
             }
         }
     }
     return -1;
 }
示例#50
0
 int InternalFindNext(ITextIterator textIterator)
 {
     //			while (textIterator.MoveAhead(1)) {
     //				if (SearchOptions.MatchCase ? MatchCaseSensitive(textIterator.TextBuffer, textIterator.Position, searchPattern) : MatchCaseInsensitive(textIterator.TextBuffer, textIterator.Position, searchPattern)) {
     //					if (!SearchOptions.MatchWholeWord || IsWholeWordAt(textIterator.TextBuffer, textIterator.Position, searchPattern.Length)) {
     //						return textIterator.Position;
     //					}
     //				}
     //			}
     return -1;
 }
示例#51
0
 public SearchResultMatch FindNext(ITextIterator textIterator, int offset, int length)
 {
     int foundOffset = InternalFindNext(textIterator, offset, length);
     return GetSearchResult(foundOffset);
 }
示例#52
0
 /// <summary>
 /// Determines if there is a whitespace before given position
 /// </summary>
 public static bool IsWhitespaceBeforePosition(ITextIterator iterator, int position) {
     char charBefore = position > 0 ? iterator[position - 1] : 'x';
     return Char.IsWhiteSpace(charBefore);
 }