Revision: 4705 http://geany.svn.sourceforge.net/geany/?rev=4705&view=rev Author: ntrel Date: 2010-02-25 18:30:43 +0000 (Thu, 25 Feb 2010)
Log Message: ----------- Implement single POSIX regex replacement - escape replacements are done with utils_str_replace_escape(). Warning: regex backreference replacement is still to do. Make utils_str_replace_escape() accept unnecessary escapes (e.g. '\e' goes to 'e').
Modified Paths: -------------- branches/gnu-regex/ChangeLog branches/gnu-regex/src/document.c branches/gnu-regex/src/utils.c
Modified: branches/gnu-regex/ChangeLog =================================================================== --- branches/gnu-regex/ChangeLog 2010-02-24 15:27:12 UTC (rev 4704) +++ branches/gnu-regex/ChangeLog 2010-02-25 18:30:43 UTC (rev 4705) @@ -1,3 +1,13 @@ +2010-02-25 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com> + + * src/utils.c, src/document.c: + Implement single POSIX regex replacement - escape replacements are + done with utils_str_replace_escape(). + Warning: regex backreference replacement is still to do. + Make utils_str_replace_escape() accept unnecessary escapes (e.g. + '\e' goes to 'e'). + + 2010-02-24 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/keybindings.c, doc/geany.txt, doc/geany.html:
Modified: branches/gnu-regex/src/document.c =================================================================== --- branches/gnu-regex/src/document.c 2010-02-24 15:27:12 UTC (rev 4704) +++ branches/gnu-regex/src/document.c 2010-02-25 18:30:43 UTC (rev 4705) @@ -2063,6 +2063,59 @@ }
+static gint geany_replace_target(ScintillaObject *sci, const gchar *replace_text, + gboolean regex) +{ + GString *str; + gint ret = 0; + gint i = 0; + + if (!regex) + return sci_replace_target(sci, replace_text, FALSE); + + str = g_string_new(replace_text); + while (str->str[i]) + { + gchar *ptr = &str->str[i]; + gchar *grp; + gchar c; + + if (ptr[0] != '\') + { + i++; + continue; + } + if (ptr[1] == '\') + { + /* backslash escape, leave for later */ + i += 2; + continue; + } + c = ptr[1]; + if (!isdigit(c)) + { + /* unnecessary escape */ + i += 2; + continue; + } + /* digit escape */ + g_string_erase(str, i, 2); + grp = "{group}"; + g_string_insert(str, i, grp); + i += strlen(grp); + } + /* now fix backslash, tabs, etc */ + if (!utils_str_replace_escape(str->str)) + { + /* 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; +} + + /* Replaces the selection if it matches, otherwise just finds the next match. * Returns: start of replaced text, or -1 if no replacement was made */ gint document_replace_text(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text, @@ -2104,7 +2157,7 @@ gint replace_len; /* search next/prev will select matching text, which we use to set the replace target */ sci_target_from_selection(doc->editor->sci); - replace_len = sci_replace_target(doc->editor->sci, replace_text, flags & SCFIND_REGEXP); + replace_len = geany_replace_target(doc->editor->sci, replace_text, flags & SCFIND_REGEXP); /* select the replacement - find text will skip past the selected text */ sci_set_selection_start(doc->editor->sci, search_pos); sci_set_selection_end(doc->editor->sci, search_pos + replace_len);
Modified: branches/gnu-regex/src/utils.c =================================================================== --- branches/gnu-regex/src/utils.c 2010-02-24 15:27:12 UTC (rev 4704) +++ branches/gnu-regex/src/utils.c 2010-02-25 18:30:43 UTC (rev 4705) @@ -1094,6 +1094,7 @@ break; #endif case 'u': + { i += 2; if (i >= strlen(string)) { @@ -1159,8 +1160,10 @@ return FALSE; } break; + } default: - return FALSE; + /* unnecessary escapes are allowed */ + string[j] = string[i]; } } else
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.