SF.net SVN: geany: [1650] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Thu Jun 28 16:00:29 UTC 2007


Revision: 1650
          http://svn.sourceforge.net/geany/?rev=1650&view=rev
Author:   ntrel
Date:     2007-06-28 09:00:29 -0700 (Thu, 28 Jun 2007)

Log Message:
-----------
Fix hang with Find All/Usage with regex '^' or '$'.
Fix replacing '^' or '$' regexes.
Use double quotes for search strings.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/document.c
    trunk/src/search.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-06-27 19:36:43 UTC (rev 1649)
+++ trunk/ChangeLog	2007-06-28 16:00:29 UTC (rev 1650)
@@ -1,3 +1,11 @@
+2007-06-28  Nick Treleaven  <nick.treleaven at btinternet.com>
+
+ * src/search.c, src/document.c:
+   Fix hang with Find All/Usage with regex '^' or '$'.
+   Fix replacing '^' or '$' regexes.
+   Use double quotes for search strings.
+
+
 2007-06-27  Enrico Tröger  <enrico.troeger at uvena.de>
 
  * src/callbacks.c, src/dialogs.c:

Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c	2007-06-27 19:36:43 UTC (rev 1649)
+++ trunk/src/document.c	2007-06-28 16:00:29 UTC (rev 1650)
@@ -1274,7 +1274,7 @@
 
 	if (count == 0)
 	{
-		ui_set_statusbar("%s", _("No matches found."));
+		ui_set_statusbar(_("No matches found for \"%s\"."), find_text);
 		return;
 	}
 
@@ -1327,21 +1327,30 @@
 	{
 		search_pos = sci_find_text(doc_list[idx].sci, flags, &ttf);
 		find_len = ttf.chrgText.cpMax - ttf.chrgText.cpMin;
-		if (search_pos == -1 || find_len == 0)
-			break;
+		if (search_pos == -1)
+			break;	// no more matches
+		if (find_len == 0 && ! NZV(replace_text))
+			break;	// nothing to do
 
 		if (search_pos + find_len > end)
-			break; //found text is partly out of range
+			break;	// found text is partly out of range
 		else
 		{
 			sci_target_start(doc_list[idx].sci, search_pos);
 			sci_target_end(doc_list[idx].sci, search_pos + find_len);
 			replace_len = sci_target_replace(doc_list[idx].sci, replace_text,
 				flags & SCFIND_REGEXP);
-			ttf.chrg.cpMin = search_pos + replace_len; //next search starts after replacement
-			end += replace_len - find_len; //update end of range now text has changed
+			count++;
+			if (search_pos == end)
+				break;	// Prevent hang when replacing regex $
+
+			// make the next search start after the replaced text
+			start = search_pos + replace_len;
+			if (find_len == 0 && replace_len == 0)
+				start++;	// skip past ^ or $ for regexes (prevents rematching)
+			ttf.chrg.cpMin = start;
+			end += replace_len - find_len;	// update end of range now text has changed
 			ttf.chrg.cpMax = end;
-			count++;
 		}
 	}
 	sci_end_undo_action(doc_list[idx].sci);

Modified: trunk/src/search.c
===================================================================
--- trunk/src/search.c	2007-06-27 19:36:43 UTC (rev 1649)
+++ trunk/src/search.c	2007-06-28 16:00:29 UTC (rev 1650)
@@ -863,9 +863,9 @@
 					gint count = search_mark(idx, search_data.text, search_data.flags);
 
 					if (count == 0)
-						ui_set_statusbar(_("No matches found for '%s'."), search_data.text);
+						ui_set_statusbar(_("No matches found for \"%s\"."), search_data.text);
 					else
-						ui_set_statusbar(_("Found %d matches for '%s'."), count,
+						ui_set_statusbar(_("Found %d matches for \"%s\"."), count,
 							search_data.text);
 				}
 				break;
@@ -1297,35 +1297,38 @@
 static gint find_document_usage(gint idx, const gchar *search_text, gint flags)
 {
 	gchar *buffer, *short_file_name;
-	gint pos, line, count = 0;
 	struct TextToFind ttf;
+	gint count = 0;
 
 	g_return_val_if_fail(DOC_IDX_VALID(idx), 0);
 
+	short_file_name = g_path_get_basename(DOC_FILENAME(idx));
+
 	ttf.chrg.cpMin = 0;
 	ttf.chrg.cpMax = sci_get_length(doc_list[idx].sci);
 	ttf.lpstrText = (gchar *)search_text;
 	while (1)
 	{
+		gint pos, line, start, find_len;
+
 		pos = sci_find_text(doc_list[idx].sci, flags, &ttf);
-		if (pos == -1) break;
+		if (pos == -1)
+			break;	// no more matches
+		find_len = ttf.chrgText.cpMax - ttf.chrgText.cpMin;
+		if (find_len == 0)
+			break;	// Ignore regex ^ or $
 
+		count++;
 		line = sci_get_line_from_position(doc_list[idx].sci, pos);
 		buffer = sci_get_line(doc_list[idx].sci, line);
-
-		if (doc_list[idx].file_name == NULL)
-			short_file_name = g_strdup(GEANY_STRING_UNTITLED);
-		else
-			short_file_name = g_path_get_basename(doc_list[idx].file_name);
-
 		msgwin_msg_add_fmt(line + 1, idx,
 			"%s:%d : %s", short_file_name, line + 1, g_strstrip(buffer));
+		g_free(buffer);
 
-		g_free(buffer);
-		g_free(short_file_name);
-		ttf.chrg.cpMin = ttf.chrgText.cpMax + 1;
-		count++;
+		start = ttf.chrgText.cpMax + 1;
+		ttf.chrg.cpMin = start;
 	}
+	g_free(short_file_name);
 	return count;
 }
 
@@ -1357,15 +1360,15 @@
 
 	if (! found) // no matches were found
 	{
-		ui_set_statusbar(_("No matches found for '%s'."), search_text);
-		msgwin_msg_add_fmt(-1, -1, _("No matches found for '%s'."), search_text);
+		ui_set_statusbar(_("No matches found for \"%s\"."), search_text);
+		msgwin_msg_add_fmt(-1, -1, _("No matches found for \"%s\"."), search_text);
 	}
 	else
 	{
 		gint count = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(msgwindow.store_msg), NULL);
 
-		ui_set_statusbar(_("Found %d matches for '%s'."), count, search_text);
-		msgwin_msg_add_fmt(-1, -1, _("Found %d matches for '%s'."), count, search_text);
+		ui_set_statusbar(_("Found %d matches for \"%s\"."), count, search_text);
+		msgwin_msg_add_fmt(-1, -1, _("Found %d matches for \"%s\"."), count, search_text);
 	}
 }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list