Fix regex search for '\\'.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/gnu-regex@4717 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2010-03-01 18:16:28 +00:00
parent 0f45597b02
commit e669410ad1
5 changed files with 28 additions and 14 deletions

View File

@ -2,6 +2,8 @@
* src/search.c:
Make regex search imply replacing escaped chars.
* src/utils.c, src/utils.h, src/search.c, src/document.c:
Fix regex search for '\\'.
2010-02-26 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>

View File

@ -2122,7 +2122,7 @@ static gint geany_replace_target(ScintillaObject *sci, const gchar *replace_text
g_free(grp);
}
/* now fix backslash, tabs, etc */
if (!utils_str_replace_escape(str->str))
if (!utils_str_replace_escape(str->str, FALSE))
{
/* replace_text should already be checked as valid */
g_assert_not_reached();

View File

@ -1077,14 +1077,18 @@ on_find_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
search_data.text = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(user_data)))));
search_data.flags = get_search_flags(find_dlg.dialog);
if (strlen(search_data.text) == 0 ||
((search_replace_escape || search_data.flags & SCFIND_REGEXP) &&
! utils_str_replace_escape(search_data.text)))
if (strlen(search_data.text) == 0)
{
fail:
utils_beep();
gtk_widget_grab_focus(find_dlg.entry);
return;
}
if (search_replace_escape || search_data.flags & SCFIND_REGEXP)
{
if (! utils_str_replace_escape(search_data.text, search_data.flags & SCFIND_REGEXP))
goto fail;
}
ui_combo_box_add_to_history(GTK_COMBO_BOX(user_data), search_data.text);
switch (response)
@ -1205,24 +1209,30 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
if ((response != GEANY_RESPONSE_FIND) && (search_flags_re & SCFIND_MATCHCASE)
&& (strcmp(find, replace) == 0))
{
fail:
utils_beep();
gtk_widget_grab_focus(replace_dlg.find_entry);
return;
}
if (search_flags_re & SCFIND_REGEXP)
{
/* we don't want to interpret escapes for replace string yet, so check a copy */
if (! utils_str_replace_escape(find, TRUE) ||
! utils_str_replace_escape(utils_strdupa(replace), TRUE))
goto fail;
}
else if (search_replace_escape_re)
{
if (! utils_str_replace_escape(find, FALSE) ||
! utils_str_replace_escape(replace, FALSE))
goto fail;
}
ui_combo_box_add_to_history(GTK_COMBO_BOX(
gtk_widget_get_parent(replace_dlg.find_entry)), find);
ui_combo_box_add_to_history(GTK_COMBO_BOX(
gtk_widget_get_parent(replace_dlg.replace_entry)), replace);
if ((search_replace_escape_re || search_flags_re & SCFIND_REGEXP) &&
(! utils_str_replace_escape(find) || ! utils_str_replace_escape(replace)))
{
utils_beep();
gtk_widget_grab_focus(replace_dlg.find_entry);
return;
}
switch (response)
{
case GEANY_RESPONSE_REPLACE_AND_FIND:

View File

@ -1046,7 +1046,7 @@ gchar **utils_read_file_in_array(const gchar *filename)
/* Contributed by Stefan Oltmanns, thanks.
* Replaces \\, \r, \n, \t and \uXXX by their real counterparts */
gboolean utils_str_replace_escape(gchar *string)
gboolean utils_str_replace_escape(gchar *string, gboolean keep_backslash)
{
gsize i, j, len;
guint unicodechar;
@ -1066,6 +1066,8 @@ gboolean utils_str_replace_escape(gchar *string)
switch (string[i])
{
case '\\':
if (keep_backslash)
string[j++] = '\\';
string[j] = '\\';
break;
case 'n':

View File

@ -180,7 +180,7 @@ GIOChannel *utils_set_up_io_channel(gint fd, GIOCondition cond, gboolean nblock,
gchar **utils_read_file_in_array(const gchar *filename);
gboolean utils_str_replace_escape(gchar *string);
gboolean utils_str_replace_escape(gchar *string, gboolean keep_backslash);
gboolean utils_wrap_string(gchar *string, gint wrapstart);