[gtksourceview/wip/search] search: return the number of replaced matches



commit 673a8e34baeef9bc72376bc1ae97f07a4fe5e177
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Jul 1 19:36:54 2013 +0200

    search: return the number of replaced matches

 gtksourceview/gtksourcebuffer.c |   22 ++++++++++++++++------
 gtksourceview/gtksourcebuffer.h |    2 +-
 gtksourceview/gtksourcesearch.c |   10 +++++++---
 gtksourceview/gtksourcesearch.h |    2 +-
 4 files changed, 25 insertions(+), 11 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index b01833a..8c81284 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -2922,15 +2922,25 @@ gtk_source_buffer_search_replace (GtkSourceBuffer   *buffer,
                                           replace_length);
 }
 
-void
+/**
+ * gtk_source_buffer_search_replace_all:
+ * @buffer: a #GtkSourceBuffer.
+ * @replace: the replacement text.
+ * @replace_length: the length of @replace in bytes, or -1.
+ *
+ * Replaces all search matches by another text.
+ *
+ * Returns: the number of replaced matches.
+ */
+guint
 gtk_source_buffer_search_replace_all (GtkSourceBuffer *buffer,
                                      const gchar     *replace,
                                      gint             replace_length)
 {
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-       g_return_if_fail (replace != NULL);
+       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), 0);
+       g_return_val_if_fail (replace != NULL, 0);
 
-       _gtk_source_search_replace_all (buffer->priv->search,
-                                       replace,
-                                       replace_length);
+       return _gtk_source_search_replace_all (buffer->priv->search,
+                                              replace,
+                                              replace_length);
 }
diff --git a/gtksourceview/gtksourcebuffer.h b/gtksourceview/gtksourcebuffer.h
index ea25786..d118ac7 100644
--- a/gtksourceview/gtksourcebuffer.h
+++ b/gtksourceview/gtksourcebuffer.h
@@ -238,7 +238,7 @@ gboolean             gtk_source_buffer_search_replace       (GtkSourceBuffer        
*buffer,
                                                                 const gchar            *replace,
                                                                 gint                    replace_length);
 
-void                    gtk_source_buffer_search_replace_all   (GtkSourceBuffer        *buffer,
+guint                   gtk_source_buffer_search_replace_all   (GtkSourceBuffer        *buffer,
                                                                 const gchar            *replace,
                                                                 gint                    replace_length);
 
diff --git a/gtksourceview/gtksourcesearch.c b/gtksourceview/gtksourcesearch.c
index 3c03d0c..a49b827 100644
--- a/gtksourceview/gtksourcesearch.c
+++ b/gtksourceview/gtksourcesearch.c
@@ -1940,7 +1940,7 @@ _gtk_source_search_replace (GtkSourceSearch   *search,
        return TRUE;
 }
 
-void
+guint
 _gtk_source_search_replace_all (GtkSourceSearch *search,
                                const gchar     *replace,
                                gint             replace_length)
@@ -1948,9 +1948,10 @@ _gtk_source_search_replace_all (GtkSourceSearch *search,
        GtkTextIter iter;
        GtkTextIter match_start;
        GtkTextIter match_end;
+       guint nb_matches_replaced = 0;
 
-       g_return_if_fail (GTK_SOURCE_IS_SEARCH (search));
-       g_return_if_fail (replace != NULL);
+       g_return_val_if_fail (GTK_SOURCE_IS_SEARCH (search), 0);
+       g_return_val_if_fail (replace != NULL, 0);
 
        gtk_text_buffer_get_start_iter (search->priv->buffer, &iter);
 
@@ -1962,7 +1963,10 @@ _gtk_source_search_replace_all (GtkSourceSearch *search,
                gtk_text_buffer_insert (search->priv->buffer, &match_end, replace, replace_length);
 
                iter = match_end;
+               nb_matches_replaced++;
        }
 
        gtk_text_buffer_end_user_action (search->priv->buffer);
+
+       return nb_matches_replaced;
 }
diff --git a/gtksourceview/gtksourcesearch.h b/gtksourceview/gtksourcesearch.h
index 181b3d6..e240afd 100644
--- a/gtksourceview/gtksourcesearch.h
+++ b/gtksourceview/gtksourcesearch.h
@@ -142,7 +142,7 @@ gboolean            _gtk_source_search_replace                      (GtkSourceSearch      
  *search,
                                                                         gint                    
replace_length);
 
 G_GNUC_INTERNAL
-void                   _gtk_source_search_replace_all                  (GtkSourceSearch        *search,
+guint                  _gtk_source_search_replace_all                  (GtkSourceSearch        *search,
                                                                         const gchar            *replace,
                                                                         gint                    
replace_length);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]