[Monodevelop-patches-list] r756 - in trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search: SearchStrategy TextIterator

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Mon Feb 2 18:21:20 EST 2004


Author: benm
Date: 2004-02-02 18:21:20 -0500 (Mon, 02 Feb 2004)
New Revision: 756

Modified:
   trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/SearchStrategy/BruteForceSearchStrategy.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/SearchStrategy/KMPSearchStrategy.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/SearchStrategy/RegExSearchStrategy.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/SearchStrategy/WildcardSearchStrategy.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/TextIterator/ForwardTextIterator.cs
   trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/TextIterator/ITextIterator.cs
Log:
refactorize

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/SearchStrategy/BruteForceSearchStrategy.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/SearchStrategy/BruteForceSearchStrategy.cs	2004-02-02 19:40:02 UTC (rev 755)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/SearchStrategy/BruteForceSearchStrategy.cs	2004-02-02 23:21:20 UTC (rev 756)
@@ -19,38 +19,32 @@
 	{
 		string searchPattern;
 		
-		bool MatchCaseSensitive(ITextBufferStrategy document, int offset, string pattern)
+		bool MatchCaseSensitive(ITextIterator iter, int offset, string pattern)
 		{
 			for (int i = 0; i < pattern.Length; ++i) {
-				if (offset + i >= document.Length || document.GetCharAt(offset + i) != pattern[i]) {
+				if (offset + i >= iter.Length || iter.GetCharAt(offset + i) != pattern[i]) {
 					return false;
 				}
 			}
 			return true;
 		}
 		
-		bool MatchCaseInsensitive(ITextBufferStrategy document, int offset, string pattern)
+		bool MatchCaseInsensitive(ITextIterator iter, int offset, string pattern)
 		{
 			for (int i = 0; i < pattern.Length; ++i) {
-				if (offset + i >= document.Length || Char.ToUpper(document.GetCharAt(offset + i)) != pattern[i]) {
+				if (offset + i >= iter.Length || Char.ToUpper(iter.GetCharAt(offset + i)) != pattern[i]) {
 					return false;
 				}
 			}
 			return true;
 		}
 		
-		bool IsWholeWordAt(ITextBufferStrategy document, int offset, int length)
-		{
-			return (offset - 1 < 0 || Char.IsWhiteSpace(document.GetCharAt(offset - 1))) &&
-			       (offset + length + 1 >= document.Length || Char.IsWhiteSpace(document.GetCharAt(offset + length)));
-		}
-		
 		int InternalFindNext(ITextIterator textIterator, SearchOptions options)
 		{
 			while (textIterator.MoveAhead(1)) {
-				if (options.IgnoreCase ? MatchCaseInsensitive(textIterator.TextBuffer, textIterator.Position, searchPattern) :
-				                         MatchCaseSensitive(textIterator.TextBuffer, textIterator.Position, searchPattern)) {
-					if (!options.SearchWholeWordOnly || IsWholeWordAt(textIterator.TextBuffer, textIterator.Position, searchPattern.Length)) {
+				if (options.IgnoreCase ? MatchCaseInsensitive(textIterator, textIterator.Position, searchPattern) :
+				                         MatchCaseSensitive(textIterator, textIterator.Position, searchPattern)) {
+					if (!options.SearchWholeWordOnly || textIterator.IsWholeWordAt (textIterator.Position, searchPattern.Length)) {
 						return textIterator.Position;
 					}
 				}

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/SearchStrategy/KMPSearchStrategy.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/SearchStrategy/KMPSearchStrategy.cs	2004-02-02 19:40:02 UTC (rev 755)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/SearchStrategy/KMPSearchStrategy.cs	2004-02-02 23:21:20 UTC (rev 756)
@@ -53,7 +53,7 @@
 					j = overlap[j];
 				}
 				if (++j >= searchPattern.Length) {
-					if ((!options.SearchWholeWordOnly || SearchReplaceUtilities.IsWholeWordAt(textIterator.TextBuffer, textIterator.Position, searchPattern.Length))) {
+					if ((!options.SearchWholeWordOnly || textIterator.IsWholeWordAt (textIterator.Position, searchPattern.Length))) {
 						return textIterator.Position;
 					}
 					if (!textIterator.MoveAhead(j - overlap[j])) {
@@ -68,7 +68,7 @@
 		{
 			int offset = InternalFindNext(textIterator, options);
 			
-			if (offset + searchPattern.Length >= textIterator.TextBuffer.Length) {
+			if (offset + searchPattern.Length >= textIterator.Length) {
 				return FindNext(textIterator, options);
 			}
 			

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/SearchStrategy/RegExSearchStrategy.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/SearchStrategy/RegExSearchStrategy.cs	2004-02-02 19:40:02 UTC (rev 755)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/SearchStrategy/RegExSearchStrategy.cs	2004-02-02 23:21:20 UTC (rev 756)
@@ -28,7 +28,7 @@
 		
 		public ISearchResult FindNext(ITextIterator textIterator, SearchOptions options)
 		{
-			string document = textIterator.TextBuffer.GetText(0, textIterator.TextBuffer.Length);
+			string document = textIterator.FullDocumentText;
 			
 			while (textIterator.MoveAhead(1)) {
 				Match m = regex.Match(document, textIterator.Position);

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/SearchStrategy/WildcardSearchStrategy.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/SearchStrategy/WildcardSearchStrategy.cs	2004-02-02 19:40:02 UTC (rev 755)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/SearchStrategy/WildcardSearchStrategy.cs	2004-02-02 23:21:20 UTC (rev 756)
@@ -82,7 +82,7 @@
 			}
 		}
 		
-		bool Match(ITextBufferStrategy document, 
+		bool Match(ITextIterator iter, 
 		           int  offset, 
 		           bool ignoreCase,
 		           int  programStart)
@@ -91,11 +91,11 @@
 			curMatchEndOffset = -1;
 			
 			for (int pc = programStart; pc < patternProgram.Count; ++pc) {
-				if (curOffset >= document.Length) {
+				if (curOffset >= iter.Length) {
 					return false;
 				}
 				
-				char    ch  = ignoreCase ? Char.ToUpper(document.GetCharAt(curOffset)) : document.GetCharAt(curOffset);
+				char    ch  = ignoreCase ? Char.ToUpper(iter.GetCharAt(curOffset)) : iter.GetCharAt(curOffset);
 				Command cmd = (Command)patternProgram[pc];
 				
 				switch (cmd.CommandType) {
@@ -105,8 +105,8 @@
 						}
 						break;
 					case CommandType.AnyZeroOrMore:
-						return Match(document, curOffset, ignoreCase, pc + 1) ||
-						       Match(document, curOffset + 1, ignoreCase, pc);
+						return Match(iter, curOffset, ignoreCase, pc + 1) ||
+						       Match(iter, curOffset + 1, ignoreCase, pc);
 					case CommandType.AnySingle:
 						break;
 					case CommandType.AnyDigit:
@@ -134,8 +134,8 @@
 		int InternalFindNext(ITextIterator textIterator, SearchOptions options)
 		{
 			while (textIterator.MoveAhead(1)) {
-				if (Match(textIterator.TextBuffer, textIterator.Position, options.IgnoreCase, 0)) {
-					if (!options.SearchWholeWordOnly || SearchReplaceUtilities.IsWholeWordAt(textIterator.TextBuffer, textIterator.Position, curMatchEndOffset - textIterator.Position)) {
+				if (Match(textIterator, textIterator.Position, options.IgnoreCase, 0)) {
+					if (!options.SearchWholeWordOnly || textIterator.IsWholeWordAt (textIterator.Position, curMatchEndOffset - textIterator.Position)) {
 						return textIterator.Position;
 					}
 				}

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/TextIterator/ForwardTextIterator.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/TextIterator/ForwardTextIterator.cs	2004-02-02 19:40:02 UTC (rev 755)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/TextIterator/ForwardTextIterator.cs	2004-02-02 23:21:20 UTC (rev 756)
@@ -56,6 +56,20 @@
 			}
 		}
 		
+		public int Length { get { return textBuffer.Length; } }
+		public string FullDocumentText { get { return textBuffer.GetText (0, textBuffer.Length); } }
+		
+		// doesnt this feel like java ;-)
+		public char GetCharAt (int p)
+		{
+			return textBuffer.GetCharAt (p);
+		}
+		
+		public bool IsWholeWordAt (int offset, int length)
+		{
+			return SearchReplaceUtilities.IsWholeWordAt (textBuffer, offset, length);
+		}
+		
 		public ForwardTextIterator(ITextBufferStrategy textBuffer, int endOffset)
 		{
 			Debug.Assert(textBuffer != null);

Modified: trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/TextIterator/ITextIterator.cs
===================================================================
--- trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/TextIterator/ITextIterator.cs	2004-02-02 19:40:02 UTC (rev 755)
+++ trunk/MonoDevelop/src/AddIns/DisplayBindings/TextEditor/Search/TextIterator/ITextIterator.cs	2004-02-02 23:21:20 UTC (rev 756)
@@ -16,13 +16,6 @@
 	public interface ITextIterator
 	{
 		/// <value>
-		/// The text buffer strategy
-		/// </value>
-		ITextBufferStrategy TextBuffer {
-			get;
-		}
-		
-		/// <value>
 		/// Gets the current char this is the same as 
 		/// GetCharRelative(0)
 		/// </value>
@@ -42,6 +35,13 @@
 			set;
 		}
 		
+		int Length { get; }
+		
+		string FullDocumentText { get; }
+		
+		bool IsWholeWordAt (int offset, int length);
+		char GetCharAt (int p);
+		
 		/// <remarks>
 		/// Gets a char relative to the current position (negative values
 		/// will work too).




More information about the Monodevelop-patches-list mailing list