コード例 #1
0
		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
ファイル: Whitespace.cs プロジェクト: Microsoft/RTVS
        /// <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);
        }
コード例 #5
0
 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);
 }
コード例 #8
0
        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;
        }
コード例 #9
0
 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
ファイル: Search.cs プロジェクト: kleinux/SharpDevelop
        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);
        }
コード例 #11
0
		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
ファイル: TextBuilder.cs プロジェクト: Microsoft/RTVS
        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
ファイル: TextBuilder.cs プロジェクト: gbull122/vscode-r
        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
ファイル: TextBuilder.cs プロジェクト: nomada2/RTVS
        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);
        }
コード例 #16
0
 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
ファイル: Whitespace.cs プロジェクト: Microsoft/RTVS
        /// <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;
        }
コード例 #18
0
		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;
		}
コード例 #19
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);
 }
コード例 #20
0
ファイル: Lint.Nodes.cs プロジェクト: ZeroInfinite/RTVS
 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
ファイル: Search.cs プロジェクト: carlhuth/GenXSource
        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
ファイル: Search.cs プロジェクト: kleinux/SharpDevelop
        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);
        }
コード例 #24
0
        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);
        }
コード例 #25
0
		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);
        }
コード例 #27
0
        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
ファイル: Whitespace.cs プロジェクト: Microsoft/RTVS
        /// <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);
        }
コード例 #31
0
 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];
         }
     }
 }
コード例 #32
0
		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;
		}
コード例 #33
0
        public SearchResult FindNext(ITextIterator textIterator)
        {
            int offset = InternalFindNext(textIterator);

            return(GetSearchResult(offset));
        }
コード例 #34
0
ファイル: Search.cs プロジェクト: xuchuansheng/GenXSource
		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
ファイル: Search.cs プロジェクト: Bombadil77/SharpDevelop
		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
ファイル: Search.cs プロジェクト: Bombadil77/SharpDevelop
		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;
		}
コード例 #38
0
 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;
 }
コード例 #41
0
 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));
        }
コード例 #44
0
        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;
        }
コード例 #45
0
        public SearchResult FindNext(ITextIterator textIterator, int offset, int length)
        {
            int foundOffset = InternalFindNext(textIterator, offset, length);

            return(GetSearchResult(foundOffset));
        }
コード例 #46
0
ファイル: Search.cs プロジェクト: xuchuansheng/GenXSource
		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;
		}
コード例 #47
0
        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
ファイル: Search.cs プロジェクト: kleinux/SharpDevelop
 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
ファイル: Whitespace.cs プロジェクト: Microsoft/RTVS
 /// <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);
 }