Revision: 4740 http://geany.svn.sourceforge.net/geany/?rev=4740&view=rev Author: ntrel Date: 2010-03-08 13:28:04 +0000 (Mon, 08 Mar 2010)
Log Message: ----------- Move search_replace_range() to search.c.
Modified Paths: -------------- branches/gnu-regex/ChangeLog branches/gnu-regex/src/document.c branches/gnu-regex/src/search.c branches/gnu-regex/src/search.h
Modified: branches/gnu-regex/ChangeLog =================================================================== --- branches/gnu-regex/ChangeLog 2010-03-08 13:23:32 UTC (rev 4739) +++ branches/gnu-regex/ChangeLog 2010-03-08 13:28:04 UTC (rev 4740) @@ -4,6 +4,8 @@ Implement POSIX-regex Find All. * src/document.c: Refactor document_replace_range() with search_replace_range(). + * src/search.c, src/search.h, src/document.c: + Move search_replace_range() to search.c.
2010-03-02 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: branches/gnu-regex/src/document.c =================================================================== --- branches/gnu-regex/src/document.c 2010-03-08 13:23:32 UTC (rev 4739) +++ branches/gnu-regex/src/document.c 2010-03-08 13:28:04 UTC (rev 4740) @@ -2086,67 +2086,6 @@ }
-/* ttf is updated to include the last match positions. - * Note: Normally you would call sci_start/end_undo_action() around this call. */ -static guint search_replace_range(ScintillaObject *sci, struct Sci_TextToFind *ttf, - gint flags, const gchar *replace_text) -{ - gint count = 0; - const gchar *find_text = ttf->lpstrText; - gint start = ttf->chrg.cpMin; - gint end = ttf->chrg.cpMax; - - g_return_val_if_fail(sci != NULL && find_text != NULL && replace_text != NULL, 0); - if (! *find_text) - return 0; - - while (TRUE) - { - gint search_pos; - gint find_len = 0, replace_len = 0; - - search_pos = sci_find_text(sci, flags, ttf); - find_len = ttf->chrgText.cpMax - ttf->chrgText.cpMin; - 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 */ - else - { - gint movepastEOL = 0; - - sci_set_target_start(sci, search_pos); - sci_set_target_end(sci, search_pos + find_len); - - if (find_len <= 0) - { - gchar chNext = sci_get_char_at(sci, sci_get_target_end(sci)); - - if (chNext == '\r' || chNext == '\n') - movepastEOL = 1; - } - replace_len = sci_replace_target(sci, replace_text, - flags & SCFIND_REGEXP); - 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 + movepastEOL; - if (find_len == 0) - start = sci_get_position_after(sci, start); /* prevent '[ ]*' regex rematching part of replaced text */ - ttf->chrg.cpMin = start; - end += replace_len - find_len; /* update end of range now text has changed */ - ttf->chrg.cpMax = end; - } - } - return count; -} - - /* Replace all text matches in a certain range within document. * If not NULL, *new_range_end is set to the new range endpoint after replacing, * or -1 if no text was found.
Modified: branches/gnu-regex/src/search.c =================================================================== --- branches/gnu-regex/src/search.c 2010-03-08 13:23:32 UTC (rev 4739) +++ branches/gnu-regex/src/search.c 2010-03-08 13:28:04 UTC (rev 4740) @@ -1876,3 +1876,64 @@ }
+/* ttf is updated to include the last match positions. + * Note: Normally you would call sci_start/end_undo_action() around this call. */ +guint search_replace_range(ScintillaObject *sci, struct Sci_TextToFind *ttf, + gint flags, const gchar *replace_text) +{ + gint count = 0; + const gchar *find_text = ttf->lpstrText; + gint start = ttf->chrg.cpMin; + gint end = ttf->chrg.cpMax; + + g_return_val_if_fail(sci != NULL && find_text != NULL && replace_text != NULL, 0); + if (! *find_text) + return 0; + + while (TRUE) + { + gint search_pos; + gint find_len = 0, replace_len = 0; + + search_pos = sci_find_text(sci, flags, ttf); + find_len = ttf->chrgText.cpMax - ttf->chrgText.cpMin; + 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 */ + else + { + gint movepastEOL = 0; + + sci_set_target_start(sci, search_pos); + sci_set_target_end(sci, search_pos + find_len); + + if (find_len <= 0) + { + gchar chNext = sci_get_char_at(sci, sci_get_target_end(sci)); + + if (chNext == '\r' || chNext == '\n') + movepastEOL = 1; + } + replace_len = sci_replace_target(sci, replace_text, + flags & SCFIND_REGEXP); + 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 + movepastEOL; + if (find_len == 0) + start = sci_get_position_after(sci, start); /* prevent '[ ]*' regex rematching part of replaced text */ + ttf->chrg.cpMin = start; + end += replace_len - find_len; /* update end of range now text has changed */ + ttf->chrg.cpMax = end; + } + } + return count; +} + +
Modified: branches/gnu-regex/src/search.h =================================================================== --- branches/gnu-regex/src/search.h 2010-03-08 13:23:32 UTC (rev 4739) +++ branches/gnu-regex/src/search.h 2010-03-08 13:28:04 UTC (rev 4740) @@ -80,4 +80,9 @@ gint search_replace_target(struct _ScintillaObject *sci, const gchar *replace_text, gboolean regex);
+struct Sci_TextToFind; + +guint search_replace_range(struct _ScintillaObject *sci, struct Sci_TextToFind *ttf, + gint flags, const gchar *replace_text); + #endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.