[gtksourceview] Various code clean-up



commit 4394b155b6e3adaca232864729420d61c0d1c75f
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Sep 25 16:01:46 2014 +0200

    Various code clean-up

 gtksourceview/gtksourcebuffer.c |  137 ++++++++++++++++++++++-----------------
 gtksourceview/gtksourceview.c   |    9 +--
 2 files changed, 81 insertions(+), 65 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index 89a13d6..d1d0385 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -2299,85 +2299,100 @@ gtk_source_buffer_iter_backward_to_context_class_toggle (GtkSourceBuffer *buffer
 }
 
 static void
-do_lower_case (GtkTextBuffer *buffer,
-               GtkTextIter   *start,
-               GtkTextIter   *end,
-               GString       *str)
+do_lower_case (GtkTextBuffer     *buffer,
+              const GtkTextIter *start,
+              const GtkTextIter *end,
+              GString           *str)
 {
-       while (!gtk_text_iter_is_end (start) &&
-              !gtk_text_iter_equal (start, end))
+       GtkTextIter iter = *start;
+
+       while (!gtk_text_iter_is_end (&iter) &&
+              !gtk_text_iter_equal (&iter, end))
        {
                gunichar c, nc;
 
-               c = gtk_text_iter_get_char (start);
+               c = gtk_text_iter_get_char (&iter);
                nc = g_unichar_tolower (c);
                g_string_append_unichar (str, nc);
 
-               gtk_text_iter_forward_char (start);
+               gtk_text_iter_forward_char (&iter);
        }
 }
 
 static void
-do_upper_case (GtkTextBuffer *buffer,
-               GtkTextIter   *start,
-               GtkTextIter   *end,
-               GString       *str)
+do_upper_case (GtkTextBuffer     *buffer,
+              const GtkTextIter *start,
+              const GtkTextIter *end,
+              GString           *str)
 {
-       while (!gtk_text_iter_is_end (start) &&
-              !gtk_text_iter_equal (start, end))
+       GtkTextIter iter = *start;
+
+       while (!gtk_text_iter_is_end (&iter) &&
+              !gtk_text_iter_equal (&iter, end))
        {
                gunichar c, nc;
 
-               c = gtk_text_iter_get_char (start);
+               c = gtk_text_iter_get_char (&iter);
                nc = g_unichar_toupper (c);
                g_string_append_unichar (str, nc);
 
-               gtk_text_iter_forward_char (start);
+               gtk_text_iter_forward_char (&iter);
        }
 }
 
 static void
-do_toggle_case (GtkTextBuffer *buffer,
-                GtkTextIter   *start,
-                GtkTextIter   *end,
-                GString       *str)
+do_toggle_case (GtkTextBuffer     *buffer,
+               const GtkTextIter *start,
+               const GtkTextIter *end,
+               GString           *str)
 {
-       while (!gtk_text_iter_is_end (start) &&
-              !gtk_text_iter_equal (start, end))
+       GtkTextIter iter = *start;
+
+       while (!gtk_text_iter_is_end (&iter) &&
+              !gtk_text_iter_equal (&iter, end))
        {
                gunichar c, nc;
 
-               c = gtk_text_iter_get_char (start);
+               c = gtk_text_iter_get_char (&iter);
                if (g_unichar_islower (c))
+               {
                        nc = g_unichar_toupper (c);
+               }
                else
+               {
                        nc = g_unichar_tolower (c);
+               }
                g_string_append_unichar (str, nc);
 
-               gtk_text_iter_forward_char (start);
+               gtk_text_iter_forward_char (&iter);
        }
 }
 
 static void
-do_title_case (GtkTextBuffer *buffer,
-               GtkTextIter   *start,
-               GtkTextIter   *end,
-               GString       *str)
+do_title_case (GtkTextBuffer     *buffer,
+              const GtkTextIter *start,
+              const GtkTextIter *end,
+              GString           *str)
 {
+       GtkTextIter iter = *start;
 
-       while (!gtk_text_iter_is_end (start) &&
-              !gtk_text_iter_equal (start, end))
+       while (!gtk_text_iter_is_end (&iter) &&
+              !gtk_text_iter_equal (&iter, end))
        {
                gunichar c, nc;
 
-               c = gtk_text_iter_get_char (start);
-               if (gtk_text_iter_starts_word (start))
+               c = gtk_text_iter_get_char (&iter);
+               if (gtk_text_iter_starts_word (&iter))
+               {
                        nc = g_unichar_totitle (c);
+               }
                else
+               {
                        nc = g_unichar_tolower (c);
+               }
                g_string_append_unichar (str, nc);
 
-               gtk_text_iter_forward_char (start);
+               gtk_text_iter_forward_char (&iter);
        }
 }
 
@@ -2398,40 +2413,44 @@ gtk_source_buffer_change_case (GtkSourceBuffer         *buffer,
                                GtkTextIter             *start,
                                GtkTextIter             *end)
 {
-       GtkTextIter i;
-       GString *s;
+       GtkTextBuffer *text_buffer;
+       GString *str;
 
        g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
        g_return_if_fail (start != NULL);
        g_return_if_fail (end != NULL);
 
-       i = *start;
-       s = g_string_new (NULL);
+       text_buffer = GTK_TEXT_BUFFER (buffer);
+       str = g_string_new (NULL);
 
        switch (case_type)
        {
-       case GTK_SOURCE_CHANGE_CASE_UPPER:
-               do_upper_case (GTK_TEXT_BUFFER (buffer), &i, end, s);
-               break;
-       case GTK_SOURCE_CHANGE_CASE_LOWER:
-               do_lower_case (GTK_TEXT_BUFFER (buffer), &i, end, s);
-               break;
-       case GTK_SOURCE_CHANGE_CASE_TOGGLE:
-               do_toggle_case (GTK_TEXT_BUFFER (buffer), &i, end, s);
-               break;
-       case GTK_SOURCE_CHANGE_CASE_TITLE:
-               do_title_case (GTK_TEXT_BUFFER (buffer), &i, end, s);
-               break;
-       default:
-               g_return_if_reached ();
-       }
-
-       gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));
-       gtk_text_buffer_delete_interactive (GTK_TEXT_BUFFER (buffer), start, end, TRUE);
-       gtk_text_buffer_insert_interactive (GTK_TEXT_BUFFER (buffer), start, s->str, s->len, TRUE);
-       gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
-
-       g_string_free (s, TRUE);
+               case GTK_SOURCE_CHANGE_CASE_UPPER:
+                       do_upper_case (text_buffer, start, end, str);
+                       break;
+
+               case GTK_SOURCE_CHANGE_CASE_LOWER:
+                       do_lower_case (text_buffer, start, end, str);
+                       break;
+
+               case GTK_SOURCE_CHANGE_CASE_TOGGLE:
+                       do_toggle_case (text_buffer, start, end, str);
+                       break;
+
+               case GTK_SOURCE_CHANGE_CASE_TITLE:
+                       do_title_case (text_buffer, start, end, str);
+                       break;
+
+               default:
+                       g_return_if_reached ();
+       }
+
+       gtk_text_buffer_begin_user_action (text_buffer);
+       gtk_text_buffer_delete_interactive (text_buffer, start, end, TRUE);
+       gtk_text_buffer_insert_interactive (text_buffer, start, str->str, str->len, TRUE);
+       gtk_text_buffer_end_user_action (text_buffer);
+
+       g_string_free (str, TRUE);
 }
 
 /**
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index e54869e..a2c9856 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -160,9 +160,7 @@ struct _GtkSourceViewPrivate
 
        GdkRGBA          current_line_color;
 
-       GtkSourceCompletion     *completion;
-
-       gint             num_line_digits;
+       GtkSourceCompletion *completion;
 
        guint            right_margin_pos;
        gint             cached_right_margin_pos;
@@ -3809,7 +3807,7 @@ gtk_source_view_get_show_right_margin (GtkSourceView *view)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
 
-       return (view->priv->show_right_margin != FALSE);
+       return view->priv->show_right_margin;
 }
 
 /**
@@ -4284,8 +4282,7 @@ gtk_source_view_get_completion (GtkSourceView *view)
  * Returns the #GtkSourceGutter object associated with @window_type for @view.
  * Only GTK_TEXT_WINDOW_LEFT and GTK_TEXT_WINDOW_RIGHT are supported,
  * respectively corresponding to the left and right gutter. The line numbers
- * and mark category icons are rendered in the gutter corresponding to
- * GTK_TEXT_WINDOW_LEFT.
+ * and mark category icons are rendered in the left gutter.
  *
  * Since: 2.8
  *


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