From 206d27c66761cedebec8bedcaa91bf9f08846095 Mon Sep 17 00:00:00 2001 From: "V.Barkov" Date: Sun, 20 Nov 2016 09:36:10 +0300 Subject: Implemented regexp finding --- pluma/dialogs/pluma-search-dialog.c | 20 +++++ pluma/dialogs/pluma-search-dialog.h | 4 + pluma/dialogs/pluma-search-dialog.ui | 27 +++++- pluma/pluma-commands-search.c | 3 + pluma/pluma-document.c | 165 ++++++++++++++++++++--------------- pluma/pluma-document.h | 8 +- pluma/pluma-utils.c | 95 ++++++++++++++++++++ pluma/pluma-utils.h | 9 ++ 8 files changed, 255 insertions(+), 76 deletions(-) diff --git a/pluma/dialogs/pluma-search-dialog.c b/pluma/dialogs/pluma-search-dialog.c index 329e1721..6263b937 100755 --- a/pluma/dialogs/pluma-search-dialog.c +++ b/pluma/dialogs/pluma-search-dialog.c @@ -68,6 +68,7 @@ struct _PlumaSearchDialogPrivate GtkWidget *replace_entry; GtkWidget *replace_text_entry; GtkWidget *match_case_checkbutton; + GtkWidget *match_regex_checkbutton; GtkWidget *entire_word_checkbutton; GtkWidget *backwards_checkbutton; GtkWidget *wrap_around_checkbutton; @@ -352,6 +353,7 @@ pluma_search_dialog_init (PlumaSearchDialog *dlg) "search_label", &dlg->priv->search_label, "replace_with_label", &dlg->priv->replace_label, "match_case_checkbutton", &dlg->priv->match_case_checkbutton, + "match_regex_checkbutton",&dlg->priv->match_regex_checkbutton, "entire_word_checkbutton", &dlg->priv->entire_word_checkbutton, "search_backwards_checkbutton", &dlg->priv->backwards_checkbutton, "wrap_around_checkbutton", &dlg->priv->wrap_around_checkbutton, @@ -582,6 +584,24 @@ pluma_search_dialog_get_match_case (PlumaSearchDialog *dialog) return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->match_case_checkbutton)); } +void +pluma_search_dialog_set_match_regex (PlumaSearchDialog *dialog, + gboolean match_case) +{ + g_return_if_fail (PLUMA_IS_SEARCH_DIALOG (dialog)); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->match_regex_checkbutton), + match_case); +} + +gboolean +pluma_search_dialog_get_match_regex (PlumaSearchDialog *dialog) +{ + g_return_val_if_fail (PLUMA_IS_SEARCH_DIALOG (dialog), FALSE); + + return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->match_regex_checkbutton)); +} + void pluma_search_dialog_set_entire_word (PlumaSearchDialog *dialog, gboolean entire_word) diff --git a/pluma/dialogs/pluma-search-dialog.h b/pluma/dialogs/pluma-search-dialog.h index fb92efba..e6ebe8dc 100755 --- a/pluma/dialogs/pluma-search-dialog.h +++ b/pluma/dialogs/pluma-search-dialog.h @@ -111,6 +111,10 @@ void pluma_search_dialog_set_match_case (PlumaSearchDialog *dialog, gboolean match_case); gboolean pluma_search_dialog_get_match_case (PlumaSearchDialog *dialog); +void pluma_search_dialog_set_match_regex (PlumaSearchDialog *dialog, + gboolean match_case); +gboolean pluma_search_dialog_get_match_regex (PlumaSearchDialog *dialog); + void pluma_search_dialog_set_entire_word (PlumaSearchDialog *dialog, gboolean entire_word); gboolean pluma_search_dialog_get_entire_word (PlumaSearchDialog *dialog); diff --git a/pluma/dialogs/pluma-search-dialog.ui b/pluma/dialogs/pluma-search-dialog.ui index a1a37b5d..b7b70aca 100644 --- a/pluma/dialogs/pluma-search-dialog.ui +++ b/pluma/dialogs/pluma-search-dialog.ui @@ -180,6 +180,22 @@ Author: Wolfgang Ulbrich 0 + + + Match _regular expression + True + True + False + start + True + True + + + False + False + 1 + + Match _entire word only @@ -193,7 +209,7 @@ Author: Wolfgang Ulbrich False False - 1 + 2 @@ -209,7 +225,7 @@ Author: Wolfgang Ulbrich False False - 2 + 3 @@ -226,7 +242,7 @@ Author: Wolfgang Ulbrich False False - 3 + 4 @@ -243,7 +259,7 @@ Author: Wolfgang Ulbrich False False - 4 + 5 @@ -268,5 +284,8 @@ Author: Wolfgang Ulbrich replace_button find_next_button + + + diff --git a/pluma/pluma-commands-search.c b/pluma/pluma-commands-search.c index 1a75dbca..03b8048a 100644 --- a/pluma/pluma-commands-search.c +++ b/pluma/pluma-commands-search.c @@ -227,6 +227,7 @@ do_find (PlumaSearchDialog *dialog, gchar *search_text; const gchar *entry_text; gboolean match_case; + gboolean match_regex; gboolean entire_word; gboolean wrap_around; gboolean search_backwards; @@ -244,6 +245,7 @@ do_find (PlumaSearchDialog *dialog, doc = PLUMA_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view))); match_case = pluma_search_dialog_get_match_case (dialog); + match_regex = pluma_search_dialog_get_match_regex(dialog); entire_word = pluma_search_dialog_get_entire_word (dialog); search_backwards = pluma_search_dialog_get_backwards (dialog); wrap_around = pluma_search_dialog_get_wrap_around (dialog); @@ -257,6 +259,7 @@ do_find (PlumaSearchDialog *dialog, PLUMA_SEARCH_SET_CASE_SENSITIVE (flags, match_case); PLUMA_SEARCH_SET_ENTIRE_WORD (flags, entire_word); + PLUMA_SEARCH_SET_MATCH_REGEX (flags, match_regex); search_text = pluma_document_get_search_text (doc, &old_flags); diff --git a/pluma/pluma-document.c b/pluma/pluma-document.c index 85890566..43abf989 100644 --- a/pluma/pluma-document.c +++ b/pluma/pluma-document.c @@ -1919,12 +1919,23 @@ pluma_document_search_forward (PlumaDocument *doc, while (!found) { - found = gtk_text_iter_forward_search (&iter, - doc->priv->search_text, - search_flags, - &m_start, - &m_end, - end); + if(!PLUMA_SEARCH_IS_MATCH_REGEX(doc->priv->search_flags)) + { + found = gtk_text_iter_forward_search (&iter, + doc->priv->search_text, + search_flags, + &m_start, + &m_end, + end); + }else{ + found = pluma_gtk_text_iter_regex_search (&iter, + doc->priv->search_text, + search_flags, + &m_start, + &m_end, + end, + TRUE); + } if (found && PLUMA_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags)) { @@ -1957,71 +1968,83 @@ pluma_document_search_forward (PlumaDocument *doc, **/ gboolean pluma_document_search_backward (PlumaDocument *doc, - const GtkTextIter *start, - const GtkTextIter *end, - GtkTextIter *match_start, - GtkTextIter *match_end) -{ - GtkTextIter iter; - GtkTextSearchFlags search_flags; - gboolean found = FALSE; - GtkTextIter m_start; - GtkTextIter m_end; - - g_return_val_if_fail (PLUMA_IS_DOCUMENT (doc), FALSE); - g_return_val_if_fail ((start == NULL) || - (gtk_text_iter_get_buffer (start) == GTK_TEXT_BUFFER (doc)), FALSE); - g_return_val_if_fail ((end == NULL) || - (gtk_text_iter_get_buffer (end) == GTK_TEXT_BUFFER (doc)), FALSE); - - if (doc->priv->search_text == NULL) - { - pluma_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == NULL\n"); - return FALSE; - } - else - pluma_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == \"%s\"\n", doc->priv->search_text); - - if (end == NULL) - gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &iter); - else - iter = *end; - - search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY; - - if (!PLUMA_SEARCH_IS_CASE_SENSITIVE (doc->priv->search_flags)) - { - search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE; - } - - while (!found) - { - found = gtk_text_iter_backward_search (&iter, - doc->priv->search_text, - search_flags, - &m_start, - &m_end, - start); - - if (found && PLUMA_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags)) - { - found = gtk_text_iter_starts_word (&m_start) && - gtk_text_iter_ends_word (&m_end); - - if (!found) - iter = m_start; - } - else - break; - } - - if (found && (match_start != NULL)) - *match_start = m_start; - - if (found && (match_end != NULL)) - *match_end = m_end; - - return found; + const GtkTextIter *start, + const GtkTextIter *end, + GtkTextIter *match_start, + GtkTextIter *match_end) +{ + GtkTextIter iter; + GtkTextSearchFlags search_flags; + gboolean found = FALSE; + GtkTextIter m_start; + GtkTextIter m_end; + + g_return_val_if_fail (PLUMA_IS_DOCUMENT (doc), FALSE); + g_return_val_if_fail ((start == NULL) || + (gtk_text_iter_get_buffer (start) == GTK_TEXT_BUFFER (doc)), FALSE); + g_return_val_if_fail ((end == NULL) || + (gtk_text_iter_get_buffer (end) == GTK_TEXT_BUFFER (doc)), FALSE); + + if (doc->priv->search_text == NULL) + { + pluma_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == NULL\n"); + return FALSE; + } + else + pluma_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == \"%s\"\n", doc->priv->search_text); + + if (end == NULL) + gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &iter); + else + iter = *end; + + search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY; + + if (!PLUMA_SEARCH_IS_CASE_SENSITIVE (doc->priv->search_flags)) + { + search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE; + } + + while (!found) + { + if(!PLUMA_SEARCH_IS_MATCH_REGEX(doc->priv->search_flags)) + { + found = gtk_text_iter_backward_search (&iter, + doc->priv->search_text, + search_flags, + &m_start, + &m_end, + start); + } + else{ + found = pluma_gtk_text_iter_regex_search (&iter, + doc->priv->search_text, + search_flags, + &m_start, + &m_end, + end, + FALSE); + } + + if (found && PLUMA_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags)) + { + found = gtk_text_iter_starts_word (&m_start) && + gtk_text_iter_ends_word (&m_end); + + if (!found) + iter = m_start; + } + else + break; + } + + if (found && (match_start != NULL)) + *match_start = m_start; + + if (found && (match_end != NULL)) + *match_end = m_end; + + return found; } /* FIXME this is an issue for introspection regardning @find */ diff --git a/pluma/pluma-document.h b/pluma/pluma-document.h index 6d90323e..ee8d6f88 100644 --- a/pluma/pluma-document.h +++ b/pluma/pluma-document.h @@ -69,7 +69,8 @@ typedef enum PLUMA_SEARCH_DONT_SET_FLAGS = 1 << 0, PLUMA_SEARCH_ENTIRE_WORD = 1 << 1, PLUMA_SEARCH_CASE_SENSITIVE = 1 << 2, - PLUMA_SEARCH_PARSE_ESCAPES = 1 << 3 + PLUMA_SEARCH_PARSE_ESCAPES = 1 << 3, + PLUMA_SEARCH_MATCH_REGEX = 1 << 4, } PlumaSearchFlags; @@ -317,6 +318,11 @@ void _pluma_document_search_region (PlumaDocument *doc, #define PLUMA_SEARCH_SET_PARSE_ESCAPES(sflags,state) ((state == TRUE) ? \ (sflags |= PLUMA_SEARCH_PARSE_ESCAPES) : (sflags &= ~PLUMA_SEARCH_PARSE_ESCAPES)) +#define PLUMA_SEARCH_IS_MATCH_REGEX(sflags) ((sflags & PLUMA_SEARCH_MATCH_REGEX) != 0) +#define PLUMA_SEARCH_SET_MATCH_REGEX(sflags,state) ((state == TRUE) ? \ +(sflags |= PLUMA_SEARCH_MATCH_REGEX) : (sflags &= ~PLUMA_SEARCH_MATCH_REGEX)) + + typedef GMountOperation *(*PlumaMountOperationFactory)(PlumaDocument *doc, gpointer userdata); diff --git a/pluma/pluma-utils.c b/pluma/pluma-utils.c index 887e9ff5..a5f67a2c 100644 --- a/pluma/pluma-utils.c +++ b/pluma/pluma-utils.c @@ -1571,3 +1571,98 @@ pluma_utils_decode_uri (const gchar *uri, return TRUE; } + +gboolean +pluma_gtk_text_iter_regex_search (const GtkTextIter *iter, + const gchar *str, + GtkTextSearchFlags flags, + GtkTextIter *match_start, + GtkTextIter *match_end, + const GtkTextIter *limit, + gboolean forward_search) +{ + GRegex *regex; + GRegexCompileFlags compile_flags; + GMatchInfo *match_info; + gchar *text; + GtkTextIter *begin_iter; + GtkTextIter *end_iter; + gchar **all_matches; + gchar *match_string; + gboolean found; + + compile_flags = 0; + if ((flags & GTK_TEXT_SEARCH_CASE_INSENSITIVE) != 0) + compile_flags |= G_REGEX_CASELESS; + + regex = g_regex_new (str,compile_flags,0,NULL); + if (regex == NULL) + return FALSE; + + begin_iter=gtk_text_iter_copy(iter); + if (limit == NULL) + { + end_iter=gtk_text_iter_copy(begin_iter); + if(forward_search) + { + gtk_text_buffer_get_end_iter(gtk_text_iter_get_buffer(begin_iter), + end_iter); + } + else + { + gtk_text_buffer_get_start_iter(gtk_text_iter_get_buffer(begin_iter), + end_iter); + } + } + else + { + end_iter=gtk_text_iter_copy(limit); + } + + if ((flags & GTK_TEXT_SEARCH_TEXT_ONLY) != 0) + { + if ((flags & GTK_TEXT_SEARCH_VISIBLE_ONLY) != 0) + text=gtk_text_iter_get_visible_text(begin_iter,end_iter); + else + text=gtk_text_iter_get_text(begin_iter,end_iter); + } + else + { + if ((flags & GTK_TEXT_SEARCH_VISIBLE_ONLY) != 0) + text=gtk_text_iter_get_visible_slice(begin_iter,end_iter); + else + text=gtk_text_iter_get_slice(begin_iter,end_iter); + } + + found = g_regex_match_all(regex,text,0,&match_info); + if (found) + { + all_matches=g_match_info_fetch_all(match_info); + if(forward_search) + { + match_string=all_matches[0]; + gtk_text_iter_forward_search(begin_iter + ,match_string + ,flags + ,match_start + ,match_end + ,limit); + } + else + { + match_string=all_matches[g_strv_length(all_matches)-1]; + gtk_text_iter_backward_search(begin_iter + ,match_string + ,flags + ,match_start + ,match_end + ,limit); + } + } + + gtk_text_iter_free(begin_iter); + gtk_text_iter_free(end_iter); + g_match_info_free (match_info); + g_regex_unref (regex); + return found; +} diff --git a/pluma/pluma-utils.h b/pluma/pluma-utils.h index 066bb438..fb62ec48 100644 --- a/pluma/pluma-utils.h +++ b/pluma/pluma-utils.h @@ -151,6 +151,15 @@ gboolean pluma_utils_decode_uri (const gchar *uri, /* Turns data from a drop into a list of well formatted uris */ gchar **pluma_utils_drop_get_uris (GtkSelectionData *selection_data); +/* Provides regexp forward search */ +gboolean +pluma_gtk_text_iter_regex_search (const GtkTextIter *iter, + const gchar *str, + GtkTextSearchFlags flags, + GtkTextIter *match_start, + GtkTextIter *match_end, + const GtkTextIter *limit, gboolean forward_search); + G_END_DECLS #endif /* __PLUMA_UTILS_H__ */ -- cgit v1.2.1 From 975393b8de593f6f6cab3cc12cfce0f34c475706 Mon Sep 17 00:00:00 2001 From: "V.Barkov" Date: Sun, 20 Nov 2016 18:55:14 +0300 Subject: Implemented replacement by regexp --- pluma/pluma-commands-search.c | 48 +++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/pluma/pluma-commands-search.c b/pluma/pluma-commands-search.c index 03b8048a..6903d381 100644 --- a/pluma/pluma-commands-search.c +++ b/pluma/pluma-commands-search.c @@ -345,7 +345,9 @@ do_replace (PlumaSearchDialog *dialog, gchar *unescaped_replace_text; gchar *selected_text = NULL; gboolean match_case; + gboolean match_regex; gboolean parse_escapes; + gboolean need_refind; doc = pluma_window_get_active_document (window); if (doc == NULL) @@ -375,20 +377,40 @@ do_replace (PlumaSearchDialog *dialog, NULL); match_case = pluma_search_dialog_get_match_case (dialog); + match_regex = pluma_search_dialog_get_match_regex(dialog); - if ((selected_text == NULL) || - (match_case && (strcmp (selected_text, unescaped_search_text) != 0)) || - (!match_case && !g_utf8_caselessnmatch (selected_text, - unescaped_search_text, - strlen (selected_text), - strlen (unescaped_search_text)) != 0)) - { - do_find (dialog, window); - g_free (unescaped_search_text); - g_free (selected_text); - - return; - } + if (selected_text != NULL) + { + if(!match_regex) + { + need_refind = (match_case && (strcmp (selected_text, + unescaped_search_text) != 0)) || + (!match_case && !g_utf8_caselessnmatch (selected_text, + unescaped_search_text, + strlen (selected_text), + strlen (unescaped_search_text)) != 0); + } + else + { + need_refind = !g_regex_match_simple(unescaped_search_text + ,selected_text, + match_case ? 0 : GTK_TEXT_SEARCH_CASE_INSENSITIVE , + 0); + } + } + else + { + need_refind = TRUE; + } + + if (need_refind) + { + do_find (dialog, window); + g_free (unescaped_search_text); + g_free (selected_text); + + return; + } unescaped_replace_text = pluma_utils_unescape_search_text (replace_entry_text); replace_selected_text (GTK_TEXT_BUFFER (doc), unescaped_replace_text); -- cgit v1.2.1 From 29f4e11f08ef02d6a3c6623b8a445502e3e98ed6 Mon Sep 17 00:00:00 2001 From: "V.Barkov" Date: Sun, 20 Nov 2016 19:28:02 +0300 Subject: Implemented "replace all" behavior for regexp --- pluma/pluma-commands-search.c | 3 +++ pluma/pluma-document.c | 37 ++++++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/pluma/pluma-commands-search.c b/pluma/pluma-commands-search.c index 6903d381..393b088a 100644 --- a/pluma/pluma-commands-search.c +++ b/pluma/pluma-commands-search.c @@ -431,6 +431,7 @@ do_replace_all (PlumaSearchDialog *dialog, const gchar *search_entry_text; const gchar *replace_entry_text; gboolean match_case; + gboolean match_regex; gboolean entire_word; gboolean parse_escapes; guint flags = 0; @@ -460,9 +461,11 @@ do_replace_all (PlumaSearchDialog *dialog, g_return_if_fail ((replace_entry_text) != NULL); match_case = pluma_search_dialog_get_match_case (dialog); + match_regex = pluma_search_dialog_get_match_regex(dialog); entire_word = pluma_search_dialog_get_entire_word (dialog); PLUMA_SEARCH_SET_CASE_SENSITIVE (flags, match_case); + PLUMA_SEARCH_SET_MATCH_REGEX (flags, match_regex); PLUMA_SEARCH_SET_ENTIRE_WORD (flags, entire_word); count = pluma_document_replace_all (doc, diff --git a/pluma/pluma-document.c b/pluma/pluma-document.c index 43abf989..11ad1372 100644 --- a/pluma/pluma-document.c +++ b/pluma/pluma-document.c @@ -2009,12 +2009,12 @@ pluma_document_search_backward (PlumaDocument *doc, { if(!PLUMA_SEARCH_IS_MATCH_REGEX(doc->priv->search_flags)) { - found = gtk_text_iter_backward_search (&iter, - doc->priv->search_text, - search_flags, - &m_start, - &m_end, - start); + found = gtk_text_iter_backward_search (&iter, + doc->priv->search_text, + search_flags, + &m_start, + &m_end, + start); } else{ found = pluma_gtk_text_iter_regex_search (&iter, @@ -2109,12 +2109,23 @@ pluma_document_replace_all (PlumaDocument *doc, do { - found = gtk_text_iter_forward_search (&iter, - search_text, - search_flags, - &m_start, - &m_end, - NULL); + if(!PLUMA_SEARCH_IS_MATCH_REGEX(flags)) + { + found = gtk_text_iter_forward_search (&iter, + search_text, + search_flags, + &m_start, + &m_end, + NULL); + }else{ + found = pluma_gtk_text_iter_regex_search (&iter, + search_text, + search_flags, + &m_start, + &m_end, + NULL, + TRUE); + } if (found && PLUMA_SEARCH_IS_ENTIRE_WORD (flags)) { @@ -2143,7 +2154,7 @@ pluma_document_replace_all (PlumaDocument *doc, replace_text_len); iter = m_start; - } + } } while (found); -- cgit v1.2.1 From 9f79aa764fa8b31b204f79ca452502204bbfa09d Mon Sep 17 00:00:00 2001 From: "V.Barkov" Date: Wed, 23 Nov 2016 21:36:51 +0300 Subject: Fixed code formatting --- pluma/pluma-commands-search.c | 77 +++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/pluma/pluma-commands-search.c b/pluma/pluma-commands-search.c index 393b088a..f4db2479 100644 --- a/pluma/pluma-commands-search.c +++ b/pluma/pluma-commands-search.c @@ -227,7 +227,7 @@ do_find (PlumaSearchDialog *dialog, gchar *search_text; const gchar *entry_text; gboolean match_case; - gboolean match_regex; + gboolean match_regex; gboolean entire_word; gboolean wrap_around; gboolean search_backwards; @@ -245,7 +245,7 @@ do_find (PlumaSearchDialog *dialog, doc = PLUMA_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view))); match_case = pluma_search_dialog_get_match_case (dialog); - match_regex = pluma_search_dialog_get_match_regex(dialog); + match_regex = pluma_search_dialog_get_match_regex(dialog); entire_word = pluma_search_dialog_get_entire_word (dialog); search_backwards = pluma_search_dialog_get_backwards (dialog); wrap_around = pluma_search_dialog_get_wrap_around (dialog); @@ -259,7 +259,7 @@ do_find (PlumaSearchDialog *dialog, PLUMA_SEARCH_SET_CASE_SENSITIVE (flags, match_case); PLUMA_SEARCH_SET_ENTIRE_WORD (flags, entire_word); - PLUMA_SEARCH_SET_MATCH_REGEX (flags, match_regex); + PLUMA_SEARCH_SET_MATCH_REGEX (flags, match_regex); search_text = pluma_document_get_search_text (doc, &old_flags); @@ -345,9 +345,9 @@ do_replace (PlumaSearchDialog *dialog, gchar *unescaped_replace_text; gchar *selected_text = NULL; gboolean match_case; - gboolean match_regex; + gboolean match_regex; gboolean parse_escapes; - gboolean need_refind; + gboolean need_refind; doc = pluma_window_get_active_document (window); if (doc == NULL) @@ -377,40 +377,39 @@ do_replace (PlumaSearchDialog *dialog, NULL); match_case = pluma_search_dialog_get_match_case (dialog); - match_regex = pluma_search_dialog_get_match_regex(dialog); + match_regex = pluma_search_dialog_get_match_regex(dialog); - if (selected_text != NULL) - { - if(!match_regex) + if (selected_text != NULL) { - need_refind = (match_case && (strcmp (selected_text, - unescaped_search_text) != 0)) || - (!match_case && !g_utf8_caselessnmatch (selected_text, - unescaped_search_text, - strlen (selected_text), - strlen (unescaped_search_text)) != 0); - } - else - { - need_refind = !g_regex_match_simple(unescaped_search_text - ,selected_text, - match_case ? 0 : GTK_TEXT_SEARCH_CASE_INSENSITIVE , - 0); - } - } - else - { - need_refind = TRUE; - } - - if (need_refind) - { - do_find (dialog, window); - g_free (unescaped_search_text); - g_free (selected_text); - - return; - } + if(!match_regex) + { + need_refind = (match_case && (strcmp (selected_text,unescaped_search_text) != 0)) + || (!match_case && !g_utf8_caselessnmatch (selected_text, + unescaped_search_text, + strlen (selected_text), + strlen (unescaped_search_text)) != 0); + } + else + { + need_refind = !g_regex_match_simple(unescaped_search_text, + selected_text, + match_case ? 0 : GTK_TEXT_SEARCH_CASE_INSENSITIVE , + 0); + } + } + else + { + need_refind = TRUE; + } + + if (need_refind) + { + do_find (dialog, window); + g_free (unescaped_search_text); + g_free (selected_text); + + return; + } unescaped_replace_text = pluma_utils_unescape_search_text (replace_entry_text); replace_selected_text (GTK_TEXT_BUFFER (doc), unescaped_replace_text); @@ -431,7 +430,7 @@ do_replace_all (PlumaSearchDialog *dialog, const gchar *search_entry_text; const gchar *replace_entry_text; gboolean match_case; - gboolean match_regex; + gboolean match_regex; gboolean entire_word; gboolean parse_escapes; guint flags = 0; @@ -465,7 +464,7 @@ do_replace_all (PlumaSearchDialog *dialog, entire_word = pluma_search_dialog_get_entire_word (dialog); PLUMA_SEARCH_SET_CASE_SENSITIVE (flags, match_case); - PLUMA_SEARCH_SET_MATCH_REGEX (flags, match_regex); + PLUMA_SEARCH_SET_MATCH_REGEX (flags, match_regex); PLUMA_SEARCH_SET_ENTIRE_WORD (flags, entire_word); count = pluma_document_replace_all (doc, -- cgit v1.2.1 From 2314b3828cbe540d65ba517c32872476417501a6 Mon Sep 17 00:00:00 2001 From: "V.Barkov" Date: Thu, 24 Nov 2016 20:18:27 +0300 Subject: Fixed formatting [2] --- pluma/dialogs/pluma-search-dialog.c | 12 +-- pluma/dialogs/pluma-search-dialog.h | 2 +- pluma/pluma-document.c | 171 +++++++++++++++++----------------- pluma/pluma-document.h | 4 +- pluma/pluma-utils.c | 180 ++++++++++++++++++------------------ pluma/pluma-utils.h | 11 +-- 6 files changed, 190 insertions(+), 190 deletions(-) diff --git a/pluma/dialogs/pluma-search-dialog.c b/pluma/dialogs/pluma-search-dialog.c index 6263b937..a77701c0 100755 --- a/pluma/dialogs/pluma-search-dialog.c +++ b/pluma/dialogs/pluma-search-dialog.c @@ -68,7 +68,7 @@ struct _PlumaSearchDialogPrivate GtkWidget *replace_entry; GtkWidget *replace_text_entry; GtkWidget *match_case_checkbutton; - GtkWidget *match_regex_checkbutton; + GtkWidget *match_regex_checkbutton; GtkWidget *entire_word_checkbutton; GtkWidget *backwards_checkbutton; GtkWidget *wrap_around_checkbutton; @@ -353,7 +353,7 @@ pluma_search_dialog_init (PlumaSearchDialog *dlg) "search_label", &dlg->priv->search_label, "replace_with_label", &dlg->priv->replace_label, "match_case_checkbutton", &dlg->priv->match_case_checkbutton, - "match_regex_checkbutton",&dlg->priv->match_regex_checkbutton, + "match_regex_checkbutton",&dlg->priv->match_regex_checkbutton, "entire_word_checkbutton", &dlg->priv->entire_word_checkbutton, "search_backwards_checkbutton", &dlg->priv->backwards_checkbutton, "wrap_around_checkbutton", &dlg->priv->wrap_around_checkbutton, @@ -588,18 +588,18 @@ void pluma_search_dialog_set_match_regex (PlumaSearchDialog *dialog, gboolean match_case) { - g_return_if_fail (PLUMA_IS_SEARCH_DIALOG (dialog)); + g_return_if_fail (PLUMA_IS_SEARCH_DIALOG (dialog)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->match_regex_checkbutton), + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->match_regex_checkbutton), match_case); } gboolean pluma_search_dialog_get_match_regex (PlumaSearchDialog *dialog) { - g_return_val_if_fail (PLUMA_IS_SEARCH_DIALOG (dialog), FALSE); + g_return_val_if_fail (PLUMA_IS_SEARCH_DIALOG (dialog), FALSE); - return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->match_regex_checkbutton)); + return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->match_regex_checkbutton)); } void diff --git a/pluma/dialogs/pluma-search-dialog.h b/pluma/dialogs/pluma-search-dialog.h index e6ebe8dc..e397b258 100755 --- a/pluma/dialogs/pluma-search-dialog.h +++ b/pluma/dialogs/pluma-search-dialog.h @@ -112,7 +112,7 @@ void pluma_search_dialog_set_match_case (PlumaSearchDialog *dialog, gboolean pluma_search_dialog_get_match_case (PlumaSearchDialog *dialog); void pluma_search_dialog_set_match_regex (PlumaSearchDialog *dialog, - gboolean match_case); + gboolean match_case); gboolean pluma_search_dialog_get_match_regex (PlumaSearchDialog *dialog); void pluma_search_dialog_set_entire_word (PlumaSearchDialog *dialog, diff --git a/pluma/pluma-document.c b/pluma/pluma-document.c index 11ad1372..3fe939f5 100644 --- a/pluma/pluma-document.c +++ b/pluma/pluma-document.c @@ -1919,24 +1919,24 @@ pluma_document_search_forward (PlumaDocument *doc, while (!found) { - if(!PLUMA_SEARCH_IS_MATCH_REGEX(doc->priv->search_flags)) - { - found = gtk_text_iter_forward_search (&iter, - doc->priv->search_text, - search_flags, - &m_start, - &m_end, - end); - }else{ - found = pluma_gtk_text_iter_regex_search (&iter, - doc->priv->search_text, - search_flags, - &m_start, - &m_end, - end, - TRUE); - } - + if(!PLUMA_SEARCH_IS_MATCH_REGEX(doc->priv->search_flags)) + { + found = gtk_text_iter_forward_search (&iter, + doc->priv->search_text, + search_flags, + &m_start, + &m_end, + end); + }else{ + found = pluma_gtk_text_iter_regex_search (&iter, + doc->priv->search_text, + search_flags, + &m_start, + &m_end, + end, + TRUE); + } + if (found && PLUMA_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags)) { found = gtk_text_iter_starts_word (&m_start) && @@ -1973,78 +1973,79 @@ pluma_document_search_backward (PlumaDocument *doc, GtkTextIter *match_start, GtkTextIter *match_end) { - GtkTextIter iter; - GtkTextSearchFlags search_flags; - gboolean found = FALSE; - GtkTextIter m_start; - GtkTextIter m_end; - - g_return_val_if_fail (PLUMA_IS_DOCUMENT (doc), FALSE); - g_return_val_if_fail ((start == NULL) || - (gtk_text_iter_get_buffer (start) == GTK_TEXT_BUFFER (doc)), FALSE); - g_return_val_if_fail ((end == NULL) || - (gtk_text_iter_get_buffer (end) == GTK_TEXT_BUFFER (doc)), FALSE); - - if (doc->priv->search_text == NULL) - { - pluma_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == NULL\n"); - return FALSE; - } - else - pluma_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == \"%s\"\n", doc->priv->search_text); - - if (end == NULL) - gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &iter); - else - iter = *end; - - search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY; - - if (!PLUMA_SEARCH_IS_CASE_SENSITIVE (doc->priv->search_flags)) - { - search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE; - } - - while (!found) - { - if(!PLUMA_SEARCH_IS_MATCH_REGEX(doc->priv->search_flags)) - { - found = gtk_text_iter_backward_search (&iter, - doc->priv->search_text, - search_flags, - &m_start, - &m_end, - start); - } - else{ - found = pluma_gtk_text_iter_regex_search (&iter, - doc->priv->search_text, - search_flags, - &m_start, - &m_end, - end, - FALSE); - } + GtkTextIter iter; + GtkTextSearchFlags search_flags; + gboolean found = FALSE; + GtkTextIter m_start; + GtkTextIter m_end; - if (found && PLUMA_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags)) - { - found = gtk_text_iter_starts_word (&m_start) && - gtk_text_iter_ends_word (&m_end); + g_return_val_if_fail (PLUMA_IS_DOCUMENT (doc), FALSE); + g_return_val_if_fail ((start == NULL) || +( gtk_text_iter_get_buffer (start) == GTK_TEXT_BUFFER (doc)), FALSE); + g_return_val_if_fail ((end == NULL) || + (gtk_text_iter_get_buffer (end) == GTK_TEXT_BUFFER (doc)), FALSE); - if (!found) - iter = m_start; - } - else - break; - } + if (doc->priv->search_text == NULL) + { + pluma_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == NULL\n"); + return FALSE; + } + else + pluma_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == \"%s\"\n", doc->priv->search_text); + + if (end == NULL) + gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &iter); + else + iter = *end; + + search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY; + + if (!PLUMA_SEARCH_IS_CASE_SENSITIVE (doc->priv->search_flags)) + { + search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE; + } + + while (!found) + { + if(!PLUMA_SEARCH_IS_MATCH_REGEX(doc->priv->search_flags)) + { + found = gtk_text_iter_backward_search (&iter, + doc->priv->search_text, + search_flags, + &m_start, + &m_end, + start); + } + else + { + found = pluma_gtk_text_iter_regex_search (&iter, + doc->priv->search_text, + search_flags, + &m_start, + &m_end, + end, + FALSE); + } - if (found && (match_start != NULL)) - *match_start = m_start; + if (found && PLUMA_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags)) + { + found = gtk_text_iter_starts_word (&m_start) && + gtk_text_iter_ends_word (&m_end); - if (found && (match_end != NULL)) - *match_end = m_end; + if (!found) + iter = m_start; + } + else + break; + } + + if (found && (match_start != NULL)) + *match_start = m_start; + + if (found && (match_end != NULL)) + *match_end = m_end; - return found; + return found; } /* FIXME this is an issue for introspection regardning @find */ diff --git a/pluma/pluma-document.h b/pluma/pluma-document.h index ee8d6f88..a8d64895 100644 --- a/pluma/pluma-document.h +++ b/pluma/pluma-document.h @@ -69,8 +69,8 @@ typedef enum PLUMA_SEARCH_DONT_SET_FLAGS = 1 << 0, PLUMA_SEARCH_ENTIRE_WORD = 1 << 1, PLUMA_SEARCH_CASE_SENSITIVE = 1 << 2, - PLUMA_SEARCH_PARSE_ESCAPES = 1 << 3, - PLUMA_SEARCH_MATCH_REGEX = 1 << 4, + PLUMA_SEARCH_PARSE_ESCAPES = 1 << 3, + PLUMA_SEARCH_MATCH_REGEX = 1 << 4, } PlumaSearchFlags; diff --git a/pluma/pluma-utils.c b/pluma/pluma-utils.c index a5f67a2c..868a5bd8 100644 --- a/pluma/pluma-utils.c +++ b/pluma/pluma-utils.c @@ -1574,95 +1574,95 @@ pluma_utils_decode_uri (const gchar *uri, gboolean pluma_gtk_text_iter_regex_search (const GtkTextIter *iter, - const gchar *str, - GtkTextSearchFlags flags, - GtkTextIter *match_start, - GtkTextIter *match_end, - const GtkTextIter *limit, - gboolean forward_search) + const gchar *str, + GtkTextSearchFlags flags, + GtkTextIter *match_start, + GtkTextIter *match_end, + const GtkTextIter *limit, + gboolean forward_search) { - GRegex *regex; - GRegexCompileFlags compile_flags; - GMatchInfo *match_info; - gchar *text; - GtkTextIter *begin_iter; - GtkTextIter *end_iter; - gchar **all_matches; - gchar *match_string; - gboolean found; - - compile_flags = 0; - if ((flags & GTK_TEXT_SEARCH_CASE_INSENSITIVE) != 0) - compile_flags |= G_REGEX_CASELESS; - - regex = g_regex_new (str,compile_flags,0,NULL); - if (regex == NULL) - return FALSE; - - begin_iter=gtk_text_iter_copy(iter); - if (limit == NULL) - { - end_iter=gtk_text_iter_copy(begin_iter); - if(forward_search) - { - gtk_text_buffer_get_end_iter(gtk_text_iter_get_buffer(begin_iter), - end_iter); - } - else - { - gtk_text_buffer_get_start_iter(gtk_text_iter_get_buffer(begin_iter), - end_iter); - } - } - else - { - end_iter=gtk_text_iter_copy(limit); - } - - if ((flags & GTK_TEXT_SEARCH_TEXT_ONLY) != 0) - { - if ((flags & GTK_TEXT_SEARCH_VISIBLE_ONLY) != 0) - text=gtk_text_iter_get_visible_text(begin_iter,end_iter); - else - text=gtk_text_iter_get_text(begin_iter,end_iter); - } - else - { - if ((flags & GTK_TEXT_SEARCH_VISIBLE_ONLY) != 0) - text=gtk_text_iter_get_visible_slice(begin_iter,end_iter); - else - text=gtk_text_iter_get_slice(begin_iter,end_iter); - } - - found = g_regex_match_all(regex,text,0,&match_info); - if (found) - { - all_matches=g_match_info_fetch_all(match_info); - if(forward_search) - { - match_string=all_matches[0]; - gtk_text_iter_forward_search(begin_iter - ,match_string - ,flags - ,match_start - ,match_end - ,limit); - } - else - { - match_string=all_matches[g_strv_length(all_matches)-1]; - gtk_text_iter_backward_search(begin_iter - ,match_string - ,flags - ,match_start - ,match_end - ,limit); - } - } - - gtk_text_iter_free(begin_iter); - gtk_text_iter_free(end_iter); - g_match_info_free (match_info); - g_regex_unref (regex); - return found; + GRegex *regex; + GRegexCompileFlags compile_flags; + GMatchInfo *match_info; + gchar *text; + GtkTextIter *begin_iter; + GtkTextIter *end_iter; + gchar **all_matches; + gchar *match_string; + gboolean found; + + compile_flags = 0; + if ((flags & GTK_TEXT_SEARCH_CASE_INSENSITIVE) != 0) + compile_flags |= G_REGEX_CASELESS; + + regex = g_regex_new (str,compile_flags,0,NULL); + if (regex == NULL) + return FALSE; + + begin_iter=gtk_text_iter_copy(iter); + if (limit == NULL) + { + end_iter=gtk_text_iter_copy(begin_iter); + if(forward_search) + { + gtk_text_buffer_get_end_iter(gtk_text_iter_get_buffer(begin_iter), + end_iter); + } + else + { + gtk_text_buffer_get_start_iter(gtk_text_iter_get_buffer(begin_iter), + end_iter); + } + } + else + { + end_iter=gtk_text_iter_copy(limit); + } + + if ((flags & GTK_TEXT_SEARCH_TEXT_ONLY) != 0) + { + if ((flags & GTK_TEXT_SEARCH_VISIBLE_ONLY) != 0) + text=gtk_text_iter_get_visible_text(begin_iter,end_iter); + else + text=gtk_text_iter_get_text(begin_iter,end_iter); + } + else + { + if ((flags & GTK_TEXT_SEARCH_VISIBLE_ONLY) != 0) + text=gtk_text_iter_get_visible_slice(begin_iter,end_iter); + else + text=gtk_text_iter_get_slice(begin_iter,end_iter); + } + + found = g_regex_match_all(regex,text,0,&match_info); + if (found) + { + all_matches=g_match_info_fetch_all(match_info); + if(forward_search) + { + match_string=all_matches[0]; + gtk_text_iter_forward_search(begin_iter, + match_string, + flags, + match_start, + match_end, + limit); + } + else + { + match_string=all_matches[g_strv_length(all_matches)-1]; + gtk_text_iter_backward_search(begin_iter, + match_string, + flags, + match_start, + match_end, + limit); + } + } + + gtk_text_iter_free(begin_iter); + gtk_text_iter_free(end_iter); + g_match_info_free (match_info); + g_regex_unref (regex); + return found; } diff --git a/pluma/pluma-utils.h b/pluma/pluma-utils.h index fb62ec48..be54f786 100644 --- a/pluma/pluma-utils.h +++ b/pluma/pluma-utils.h @@ -154,14 +154,13 @@ gchar **pluma_utils_drop_get_uris (GtkSelectionData *selection_data); /* Provides regexp forward search */ gboolean pluma_gtk_text_iter_regex_search (const GtkTextIter *iter, - const gchar *str, - GtkTextSearchFlags flags, - GtkTextIter *match_start, - GtkTextIter *match_end, - const GtkTextIter *limit, gboolean forward_search); + const gchar *str, + GtkTextSearchFlags flags, + GtkTextIter *match_start, + GtkTextIter *match_end, + const GtkTextIter *limit, gboolean forward_search); G_END_DECLS #endif /* __PLUMA_UTILS_H__ */ - -- cgit v1.2.1 From df3b18c149e4e410988242153b2d3f26b1601d0f Mon Sep 17 00:00:00 2001 From: Vadim Barkov Date: Sun, 8 Jan 2017 16:51:21 +0300 Subject: Fixed wrong formatting --- pluma/dialogs/pluma-search-dialog.h | 2 +- pluma/pluma-utils.c | 38 ++++++++++++++++++------------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/pluma/dialogs/pluma-search-dialog.h b/pluma/dialogs/pluma-search-dialog.h index e397b258..e6ebe8dc 100755 --- a/pluma/dialogs/pluma-search-dialog.h +++ b/pluma/dialogs/pluma-search-dialog.h @@ -112,7 +112,7 @@ void pluma_search_dialog_set_match_case (PlumaSearchDialog *dialog, gboolean pluma_search_dialog_get_match_case (PlumaSearchDialog *dialog); void pluma_search_dialog_set_match_regex (PlumaSearchDialog *dialog, - gboolean match_case); + gboolean match_case); gboolean pluma_search_dialog_get_match_regex (PlumaSearchDialog *dialog); void pluma_search_dialog_set_entire_word (PlumaSearchDialog *dialog, diff --git a/pluma/pluma-utils.c b/pluma/pluma-utils.c index ff872e09..d1c701ea 100644 --- a/pluma/pluma-utils.c +++ b/pluma/pluma-utils.c @@ -1606,49 +1606,49 @@ pluma_gtk_text_iter_regex_search (const GtkTextIter *iter, if (regex == NULL) return FALSE; - begin_iter=gtk_text_iter_copy(iter); + begin_iter = gtk_text_iter_copy (iter); if (limit == NULL) { - end_iter=gtk_text_iter_copy(begin_iter); - if(forward_search) + end_iter = gtk_text_iter_copy (begin_iter); + if (forward_search) { - gtk_text_buffer_get_end_iter(gtk_text_iter_get_buffer(begin_iter), + gtk_text_buffer_get_end_iter (gtk_text_iter_get_buffer(begin_iter), end_iter); } else { - gtk_text_buffer_get_start_iter(gtk_text_iter_get_buffer(begin_iter), + gtk_text_buffer_get_start_iter (gtk_text_iter_get_buffer (begin_iter), end_iter); } } else { - end_iter=gtk_text_iter_copy(limit); + end_iter = gtk_text_iter_copy (limit); } if ((flags & GTK_TEXT_SEARCH_TEXT_ONLY) != 0) { if ((flags & GTK_TEXT_SEARCH_VISIBLE_ONLY) != 0) - text=gtk_text_iter_get_visible_text(begin_iter,end_iter); + text = gtk_text_iter_get_visible_text (begin_iter, end_iter); else - text=gtk_text_iter_get_text(begin_iter,end_iter); + text = gtk_text_iter_get_text (begin_iter, end_iter); } else { if ((flags & GTK_TEXT_SEARCH_VISIBLE_ONLY) != 0) - text=gtk_text_iter_get_visible_slice(begin_iter,end_iter); + text = gtk_text_iter_get_visible_slice (begin_iter, end_iter); else - text=gtk_text_iter_get_slice(begin_iter,end_iter); + text = gtk_text_iter_get_slice (begin_iter, end_iter); } - found = g_regex_match_all(regex,text,0,&match_info); + found = g_regex_match_all (regex,text,0,&match_info); if (found) { - all_matches=g_match_info_fetch_all(match_info); - if(forward_search) + all_matches = g_match_info_fetch_all (match_info); + if (forward_search) { - match_string=all_matches[0]; - gtk_text_iter_forward_search(begin_iter, + match_string = all_matches[0]; + gtk_text_iter_forward_search (begin_iter, match_string, flags, match_start, @@ -1657,8 +1657,8 @@ pluma_gtk_text_iter_regex_search (const GtkTextIter *iter, } else { - match_string=all_matches[g_strv_length(all_matches)-1]; - gtk_text_iter_backward_search(begin_iter, + match_string = all_matches[g_strv_length (all_matches) - 1]; + gtk_text_iter_backward_search (begin_iter, match_string, flags, match_start, @@ -1667,8 +1667,8 @@ pluma_gtk_text_iter_regex_search (const GtkTextIter *iter, } } - gtk_text_iter_free(begin_iter); - gtk_text_iter_free(end_iter); + gtk_text_iter_free (begin_iter); + gtk_text_iter_free (end_iter); g_match_info_free (match_info); g_regex_unref (regex); return found; -- cgit v1.2.1 From a79faa602fac4e4bb4c33a324150219727fa1f57 Mon Sep 17 00:00:00 2001 From: Vadim Barkov Date: Sun, 8 Jan 2017 17:51:17 +0300 Subject: Fixed wrong behaviour of search on zero length results --- pluma/pluma-utils.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/pluma/pluma-utils.c b/pluma/pluma-utils.c index d1c701ea..b8f081c0 100644 --- a/pluma/pluma-utils.c +++ b/pluma/pluma-utils.c @@ -1597,6 +1597,9 @@ pluma_gtk_text_iter_regex_search (const GtkTextIter *iter, gchar **all_matches; gchar *match_string; gboolean found; + gint non_null_result_number; + gboolean non_null_result_found; + guint result_size; compile_flags = 0; if ((flags & GTK_TEXT_SEARCH_CASE_INSENSITIVE) != 0) @@ -1645,9 +1648,38 @@ pluma_gtk_text_iter_regex_search (const GtkTextIter *iter, if (found) { all_matches = g_match_info_fetch_all (match_info); + result_size = (gint) g_strv_length (all_matches); + + if(forward_search){ + non_null_result_number = 0; + } else { + non_null_result_number = result_size - 1 ; + } + non_null_result_found = FALSE; + while((non_null_result_number >= 0) + && (non_null_result_number < result_size) ) { + + if(g_utf8_strlen (all_matches [non_null_result_number], G_MAXSSIZE) != 0) { + non_null_result_found = TRUE; + break; + } else { + if(forward_search) { + non_null_result_number++; + } else { + non_null_result_number--; + } + } + + } + + if(!non_null_result_found) { + found = FALSE; + goto free_resources; + } + + match_string = all_matches [non_null_result_number]; if (forward_search) - { - match_string = all_matches[0]; + { gtk_text_iter_forward_search (begin_iter, match_string, flags, @@ -1656,8 +1688,7 @@ pluma_gtk_text_iter_regex_search (const GtkTextIter *iter, limit); } else - { - match_string = all_matches[g_strv_length (all_matches) - 1]; + { gtk_text_iter_backward_search (begin_iter, match_string, flags, @@ -1667,6 +1698,7 @@ pluma_gtk_text_iter_regex_search (const GtkTextIter *iter, } } +free_resources: gtk_text_iter_free (begin_iter); gtk_text_iter_free (end_iter); g_match_info_free (match_info); -- cgit v1.2.1