Fix not replacing escapes within a backreference match.

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

View File

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

View File

@ -2099,17 +2099,12 @@ static gint geany_replace_target(ScintillaObject *sci, const gchar *replace_text
i++;
continue;
}
if (ptr[1] == '\\')
{
/* backslash escape, leave for later */
i += 2;
continue;
}
c = ptr[1];
if (!isdigit(c))
/* backslash or unnecessary escape */
if (c == '\\' || !isdigit(c))
{
/* unnecessary escape */
i += 2;
g_string_erase(str, i, 1);
i++;
continue;
}
/* digit escape */
@ -2121,12 +2116,6 @@ static gint geany_replace_target(ScintillaObject *sci, const gchar *replace_text
i += strlen(grp);
g_free(grp);
}
/* now fix backslash, tabs, etc */
if (!utils_str_replace_escape(str->str, FALSE))
{
/* replace_text should already be checked as valid */
g_assert_not_reached();
}
ret = sci_replace_target(sci, str->str, FALSE);
g_string_free(str, TRUE);
return ret;

View File

@ -1216,9 +1216,8 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
}
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))
! utils_str_replace_escape(replace, TRUE))
goto fail;
}
else if (search_replace_escape_re)

View File

@ -1045,7 +1045,8 @@ gchar **utils_read_file_in_array(const gchar *filename)
/* Contributed by Stefan Oltmanns, thanks.
* Replaces \\, \r, \n, \t and \uXXX by their real counterparts */
* Replaces \\, \r, \n, \t and \uXXX by their real counterparts.
* keep_backslash is used for regex strings to leave '\\' and '\?' in place */
gboolean utils_str_replace_escape(gchar *string, gboolean keep_backslash)
{
gsize i, j, len;
@ -1165,6 +1166,8 @@ gboolean utils_str_replace_escape(gchar *string, gboolean keep_backslash)
}
default:
/* unnecessary escapes are allowed */
if (keep_backslash)
string[j++] = '\\';
string[j] = string[i];
}
}