[gtksourceview/wip/chergert/gsv-gtk4: 31/84] buffer: modernize GtkSourceBufferOutputStream



commit d6a6c49030a581df28171568d4e5e27fdf70ddf9
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jan 9 13:56:00 2020 -0800

    buffer: modernize GtkSourceBufferOutputStream
    
     - Use G_DECLARE_
     - Move to -private.h
     - Make final
     - Fix multi-line function indentation

 docs/reference/meson.build                         |   2 +-
 .../gtksourcebufferoutputstream-private.h          |  49 +++
 gtksourceview/gtksourcebufferoutputstream.c        | 371 ++++++++++-----------
 gtksourceview/gtksourcebufferoutputstream.h        |  74 ----
 gtksourceview/gtksourcefileloader.c                |   2 +-
 testsuite/test-buffer-output-stream.c              |  28 +-
 6 files changed, 250 insertions(+), 276 deletions(-)
---
diff --git a/docs/reference/meson.build b/docs/reference/meson.build
index e1c0f6cd..b97f6e00 100644
--- a/docs/reference/meson.build
+++ b/docs/reference/meson.build
@@ -10,7 +10,7 @@ reference_private_h = [
   'gtksourcebuffer-private.h',
   'gtksourcebufferinputstream-private.h',
   'gtksourcebufferinternal-private.h',
-  'gtksourcebufferoutputstream.h',
+  'gtksourcebufferoutputstream-private.h',
   'gtksourcecompletion-private.h',
   'gtksourcecompletioncontainer-private.h',
   'gtksourcecompletioncontext-private.h',
diff --git a/gtksourceview/gtksourcebufferoutputstream-private.h 
b/gtksourceview/gtksourcebufferoutputstream-private.h
new file mode 100644
index 00000000..b723fa0c
--- /dev/null
+++ b/gtksourceview/gtksourcebufferoutputstream-private.h
@@ -0,0 +1,49 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
+/*
+ * This file is part of GtkSourceView
+ *
+ * Copyright 2010 - Ignacio Casal Quinteiro
+ * Copyright 2014 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+#include "gtksourcetypes.h"
+#include "gtksourcetypes-private.h"
+#include "gtksourcebuffer.h"
+#include "gtksourcefile.h"
+
+G_BEGIN_DECLS
+
+#define GTK_SOURCE_TYPE_BUFFER_OUTPUT_STREAM (gtk_source_buffer_output_stream_get_type())
+
+GTK_SOURCE_INTERNAL
+G_DECLARE_FINAL_TYPE (GtkSourceBufferOutputStream, gtk_source_buffer_output_stream, GTK_SOURCE, 
BUFFER_OUTPUT_STREAM, GOutputStream)
+
+GTK_SOURCE_INTERNAL
+GtkSourceBufferOutputStream *gtk_source_buffer_output_stream_new                 (GtkSourceBuffer            
 *buffer,
+                                                                                  GSList                     
 *candidate_encodings,
+                                                                                  gboolean                   
  remove_trailing_newline);
+GTK_SOURCE_INTERNAL
+GtkSourceNewlineType         gtk_source_buffer_output_stream_detect_newline_type 
(GtkSourceBufferOutputStream *stream);
+GTK_SOURCE_INTERNAL
+const GtkSourceEncoding     *gtk_source_buffer_output_stream_get_guessed         
(GtkSourceBufferOutputStream *stream);
+GTK_SOURCE_INTERNAL
+guint                        gtk_source_buffer_output_stream_get_num_fallbacks   
(GtkSourceBufferOutputStream *stream);
+
+G_END_DECLS
diff --git a/gtksourceview/gtksourcebufferoutputstream.c b/gtksourceview/gtksourcebufferoutputstream.c
index 32981ff9..ab41c2b5 100644
--- a/gtksourceview/gtksourcebufferoutputstream.c
+++ b/gtksourceview/gtksourcebufferoutputstream.c
@@ -21,10 +21,11 @@
 
 #include "config.h"
 
-#include "gtksourcebufferoutputstream.h"
 #include <string.h>
 #include <errno.h>
 #include <glib/gi18n-lib.h>
+
+#include "gtksourcebufferoutputstream-private.h"
 #include "gtksourcebuffer.h"
 #include "gtksourcebuffer-private.h"
 #include "gtksourceencoding.h"
@@ -55,8 +56,10 @@
 
 #define MAX_UNICHAR_LEN 6
 
-struct _GtkSourceBufferOutputStreamPrivate
+struct _GtkSourceBufferOutputStream
 {
+       GOutputStream parent_instance;
+
        GtkSourceBuffer *source_buffer;
        GtkTextIter pos;
 
@@ -92,39 +95,37 @@ enum
        PROP_REMOVE_TRAILING_NEWLINE
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceBufferOutputStream, gtk_source_buffer_output_stream, 
G_TYPE_OUTPUT_STREAM)
-
-static gssize gtk_source_buffer_output_stream_write   (GOutputStream  *stream,
-                                                      const void     *buffer,
-                                                      gsize           count,
-                                                      GCancellable   *cancellable,
-                                                      GError        **error);
+G_DEFINE_TYPE (GtkSourceBufferOutputStream, gtk_source_buffer_output_stream, G_TYPE_OUTPUT_STREAM)
 
+static gssize   gtk_source_buffer_output_stream_write (GOutputStream  *stream,
+                                                       const void     *buffer,
+                                                       gsize           count,
+                                                       GCancellable   *cancellable,
+                                                       GError        **error);
 static gboolean gtk_source_buffer_output_stream_close (GOutputStream  *stream,
-                                                      GCancellable   *cancellable,
-                                                      GError        **error);
-
+                                                       GCancellable   *cancellable,
+                                                       GError        **error);
 static gboolean gtk_source_buffer_output_stream_flush (GOutputStream  *stream,
-                                                      GCancellable   *cancellable,
-                                                      GError        **error);
+                                                       GCancellable   *cancellable,
+                                                       GError        **error);
 
 static void
 gtk_source_buffer_output_stream_set_property (GObject      *object,
-                                             guint         prop_id,
-                                             const GValue *value,
-                                             GParamSpec   *pspec)
+                                              guint         prop_id,
+                                              const GValue *value,
+                                              GParamSpec   *pspec)
 {
        GtkSourceBufferOutputStream *stream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (object);
 
        switch (prop_id)
        {
                case PROP_BUFFER:
-                       g_assert (stream->priv->source_buffer == NULL);
-                       stream->priv->source_buffer = g_value_dup_object (value);
+                       g_assert (stream->source_buffer == NULL);
+                       stream->source_buffer = g_value_dup_object (value);
                        break;
 
                case PROP_REMOVE_TRAILING_NEWLINE:
-                       stream->priv->remove_trailing_newline = g_value_get_boolean (value);
+                       stream->remove_trailing_newline = g_value_get_boolean (value);
                        break;
 
                default:
@@ -135,20 +136,20 @@ gtk_source_buffer_output_stream_set_property (GObject      *object,
 
 static void
 gtk_source_buffer_output_stream_get_property (GObject    *object,
-                                             guint       prop_id,
-                                             GValue     *value,
-                                             GParamSpec *pspec)
+                                              guint       prop_id,
+                                              GValue     *value,
+                                              GParamSpec *pspec)
 {
        GtkSourceBufferOutputStream *stream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (object);
 
        switch (prop_id)
        {
                case PROP_BUFFER:
-                       g_value_set_object (value, stream->priv->source_buffer);
+                       g_value_set_object (value, stream->source_buffer);
                        break;
 
                case PROP_REMOVE_TRAILING_NEWLINE:
-                       g_value_set_boolean (value, stream->priv->remove_trailing_newline);
+                       g_value_set_boolean (value, stream->remove_trailing_newline);
                        break;
 
                default:
@@ -162,8 +163,8 @@ gtk_source_buffer_output_stream_dispose (GObject *object)
 {
        GtkSourceBufferOutputStream *stream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (object);
 
-       g_clear_object (&stream->priv->source_buffer);
-       g_clear_object (&stream->priv->charset_conv);
+       g_clear_object (&stream->source_buffer);
+       g_clear_object (&stream->charset_conv);
 
        G_OBJECT_CLASS (gtk_source_buffer_output_stream_parent_class)->dispose (object);
 }
@@ -173,9 +174,9 @@ gtk_source_buffer_output_stream_finalize (GObject *object)
 {
        GtkSourceBufferOutputStream *stream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (object);
 
-       g_free (stream->priv->buffer);
-       g_free (stream->priv->iconv_buffer);
-       g_slist_free (stream->priv->encodings);
+       g_free (stream->buffer);
+       g_free (stream->iconv_buffer);
+       g_slist_free (stream->encodings);
 
        G_OBJECT_CLASS (gtk_source_buffer_output_stream_parent_class)->finalize (object);
 }
@@ -185,18 +186,18 @@ gtk_source_buffer_output_stream_constructed (GObject *object)
 {
        GtkSourceBufferOutputStream *stream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (object);
 
-       if (stream->priv->source_buffer == NULL)
+       if (stream->source_buffer == NULL)
        {
                g_critical ("This should never happen, a problem happened constructing the Buffer Output 
Stream!");
                return;
        }
 
-       gtk_source_buffer_begin_not_undoable_action (stream->priv->source_buffer);
+       gtk_source_buffer_begin_not_undoable_action (stream->source_buffer);
 
-       gtk_text_buffer_set_text (GTK_TEXT_BUFFER (stream->priv->source_buffer), "", 0);
-       gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->priv->source_buffer), FALSE);
+       gtk_text_buffer_set_text (GTK_TEXT_BUFFER (stream->source_buffer), "", 0);
+       gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->source_buffer), FALSE);
 
-       gtk_source_buffer_end_not_undoable_action (stream->priv->source_buffer);
+       gtk_source_buffer_end_not_undoable_action (stream->source_buffer);
 
        G_OBJECT_CLASS (gtk_source_buffer_output_stream_parent_class)->constructed (object);
 }
@@ -241,44 +242,42 @@ gtk_source_buffer_output_stream_class_init (GtkSourceBufferOutputStreamClass *kl
 static void
 gtk_source_buffer_output_stream_init (GtkSourceBufferOutputStream *stream)
 {
-       stream->priv = gtk_source_buffer_output_stream_get_instance_private (stream);
-
-       stream->priv->buffer = NULL;
-       stream->priv->buflen = 0;
+       stream->buffer = NULL;
+       stream->buflen = 0;
 
-       stream->priv->charset_conv = NULL;
-       stream->priv->encodings = NULL;
-       stream->priv->current_encoding = NULL;
+       stream->charset_conv = NULL;
+       stream->encodings = NULL;
+       stream->current_encoding = NULL;
 
-       stream->priv->error_offset = -1;
+       stream->error_offset = -1;
 
-       stream->priv->is_initialized = FALSE;
-       stream->priv->is_closed = FALSE;
-       stream->priv->is_utf8 = FALSE;
-       stream->priv->use_first = FALSE;
+       stream->is_initialized = FALSE;
+       stream->is_closed = FALSE;
+       stream->is_utf8 = FALSE;
+       stream->use_first = FALSE;
 }
 
 static const GtkSourceEncoding *
 get_encoding (GtkSourceBufferOutputStream *stream)
 {
-       if (stream->priv->current_encoding == NULL)
+       if (stream->current_encoding == NULL)
        {
-               stream->priv->current_encoding = stream->priv->encodings;
+               stream->current_encoding = stream->encodings;
        }
        else
        {
-               stream->priv->current_encoding = g_slist_next (stream->priv->current_encoding);
+               stream->current_encoding = g_slist_next (stream->current_encoding);
        }
 
-       if (stream->priv->current_encoding != NULL)
+       if (stream->current_encoding != NULL)
        {
-               return stream->priv->current_encoding->data;
+               return stream->current_encoding->data;
        }
 
-       stream->priv->use_first = TRUE;
-       stream->priv->current_encoding = stream->priv->encodings;
+       stream->use_first = TRUE;
+       stream->current_encoding = stream->encodings;
 
-       return stream->priv->current_encoding->data;
+       return stream->current_encoding->data;
 }
 
 static gboolean
@@ -355,21 +354,21 @@ try_convert (GCharsetConverter *converter,
 
 static GCharsetConverter *
 guess_encoding (GtkSourceBufferOutputStream *stream,
-               const void                  *inbuf,
-               gsize                        inbuf_size)
+                const void                  *inbuf,
+                gsize                        inbuf_size)
 {
        GCharsetConverter *conv = NULL;
 
        if (inbuf == NULL || inbuf_size == 0)
        {
-               stream->priv->is_utf8 = TRUE;
+               stream->is_utf8 = TRUE;
                return NULL;
        }
 
-       if (stream->priv->encodings != NULL &&
-           stream->priv->encodings->next == NULL)
+       if (stream->encodings != NULL &&
+           stream->encodings->next == NULL)
        {
-               stream->priv->use_first = TRUE;
+               stream->use_first = TRUE;
        }
 
        /* We just check the first block */
@@ -390,7 +389,7 @@ guess_encoding (GtkSourceBufferOutputStream *stream,
 
                DEBUG ({
                       g_print ("trying charset: %s\n",
-                               gtk_source_encoding_get_charset (stream->priv->current_encoding->data));
+                               gtk_source_encoding_get_charset (stream->current_encoding->data));
                });
 
                if (enc == gtk_source_encoding_get_utf8 ())
@@ -399,9 +398,9 @@ guess_encoding (GtkSourceBufferOutputStream *stream,
                        const gchar *end;
 
                        if (g_utf8_validate (inbuf, inbuf_size, &end) ||
-                           stream->priv->use_first)
+                           stream->use_first)
                        {
-                               stream->priv->is_utf8 = TRUE;
+                               stream->is_utf8 = TRUE;
                                break;
                        }
 
@@ -409,7 +408,7 @@ guess_encoding (GtkSourceBufferOutputStream *stream,
                        remainder = inbuf_size - (end - (gchar *)inbuf);
                        if (remainder < 6)
                        {
-                               stream->priv->is_utf8 = TRUE;
+                               stream->is_utf8 = TRUE;
                                break;
                        }
 
@@ -421,7 +420,7 @@ guess_encoding (GtkSourceBufferOutputStream *stream,
                                                NULL);
 
                /* If we tried all encodings we use the first one */
-               if (stream->priv->use_first)
+               if (stream->use_first)
                {
                        break;
                }
@@ -473,8 +472,8 @@ get_newline_type (GtkTextIter *end)
 
 GtkSourceBufferOutputStream *
 gtk_source_buffer_output_stream_new (GtkSourceBuffer *buffer,
-                                    GSList          *candidate_encodings,
-                                    gboolean         remove_trailing_newline)
+                                     GSList          *candidate_encodings,
+                                     gboolean         remove_trailing_newline)
 {
        GtkSourceBufferOutputStream *stream;
 
@@ -483,7 +482,7 @@ gtk_source_buffer_output_stream_new (GtkSourceBuffer *buffer,
                               "remove-trailing-newline", remove_trailing_newline,
                               NULL);
 
-       stream->priv->encodings = g_slist_copy (candidate_encodings);
+       stream->encodings = g_slist_copy (candidate_encodings);
 
        return stream;
 }
@@ -497,14 +496,14 @@ gtk_source_buffer_output_stream_detect_newline_type (GtkSourceBufferOutputStream
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER_OUTPUT_STREAM (stream),
                              GTK_SOURCE_NEWLINE_TYPE_DEFAULT);
 
-       if (stream->priv->source_buffer == NULL)
+       if (stream->source_buffer == NULL)
        {
                return GTK_SOURCE_NEWLINE_TYPE_DEFAULT;
        }
 
        type = GTK_SOURCE_NEWLINE_TYPE_DEFAULT;
 
-       gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (stream->priv->source_buffer),
+       gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (stream->source_buffer),
                                        &iter);
 
        if (gtk_text_iter_ends_line (&iter) || gtk_text_iter_forward_to_line_end (&iter))
@@ -520,11 +519,11 @@ gtk_source_buffer_output_stream_get_guessed (GtkSourceBufferOutputStream *stream
 {
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER_OUTPUT_STREAM (stream), NULL);
 
-       if (stream->priv->current_encoding != NULL)
+       if (stream->current_encoding != NULL)
        {
-               return stream->priv->current_encoding->data;
+               return stream->current_encoding->data;
        }
-       else if (stream->priv->is_utf8 || !stream->priv->is_initialized)
+       else if (stream->is_utf8 || !stream->is_initialized)
        {
                /* If it is not initialized we assume that we are trying to
                 * convert the empty string.
@@ -540,7 +539,7 @@ gtk_source_buffer_output_stream_get_num_fallbacks (GtkSourceBufferOutputStream *
 {
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER_OUTPUT_STREAM (stream), 0);
 
-       return stream->priv->n_fallback_errors;
+       return stream->n_fallback_errors;
 }
 
 static void
@@ -548,31 +547,31 @@ apply_error_tag (GtkSourceBufferOutputStream *stream)
 {
        GtkTextIter start;
 
-       if (stream->priv->error_offset == -1 ||
-           stream->priv->source_buffer == NULL)
+       if (stream->error_offset == -1 ||
+           stream->source_buffer == NULL)
        {
                return;
        }
 
-       gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (stream->priv->source_buffer),
-                                           &start, stream->priv->error_offset);
+       gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (stream->source_buffer),
+                                           &start, stream->error_offset);
 
-       _gtk_source_buffer_set_as_invalid_character (stream->priv->source_buffer,
+       _gtk_source_buffer_set_as_invalid_character (stream->source_buffer,
                                                     &start,
-                                                    &stream->priv->pos);
+                                                    &stream->pos);
 
-       stream->priv->error_offset = -1;
+       stream->error_offset = -1;
 }
 
 static void
 insert_fallback (GtkSourceBufferOutputStream *stream,
-                const gchar                 *buffer)
+                 const gchar                 *buffer)
 {
        guint8 out[4];
        guint8 v;
        const gchar hex[] = "0123456789ABCDEF";
 
-       if (stream->priv->source_buffer == NULL)
+       if (stream->source_buffer == NULL)
        {
                return;
        }
@@ -586,30 +585,30 @@ insert_fallback (GtkSourceBufferOutputStream *stream,
        out[2] = hex[(v & 0x0f) >> 0];
        out[3] = '\0';
 
-       gtk_text_buffer_insert (GTK_TEXT_BUFFER (stream->priv->source_buffer),
-                               &stream->priv->pos, (const gchar *)out, 3);
+       gtk_text_buffer_insert (GTK_TEXT_BUFFER (stream->source_buffer),
+                               &stream->pos, (const gchar *)out, 3);
 
-       ++stream->priv->n_fallback_errors;
+       ++stream->n_fallback_errors;
 }
 
 static void
 validate_and_insert (GtkSourceBufferOutputStream *stream,
-                    gchar                       *buffer,
-                    gsize                        count,
-                    gboolean                     owned)
+                     gchar                       *buffer,
+                     gsize                        count,
+                     gboolean                     owned)
 {
        GtkTextBuffer *text_buffer;
        GtkTextIter *iter;
        gsize len;
        gchar *free_text = NULL;
 
-       if (stream->priv->source_buffer == NULL)
+       if (stream->source_buffer == NULL)
        {
                return;
        }
 
-       text_buffer = GTK_TEXT_BUFFER (stream->priv->source_buffer);
-       iter = &stream->priv->pos;
+       text_buffer = GTK_TEXT_BUFFER (stream->source_buffer);
+       iter = &stream->pos;
        len = count;
 
        while (len != 0)
@@ -635,10 +634,10 @@ validate_and_insert (GtkSourceBufferOutputStream *stream,
 
                        if (ptr && *ptr == '\r' && ptr - buffer == (glong)len - 1)
                        {
-                               stream->priv->buffer = g_new (gchar, 2);
-                               stream->priv->buffer[0] = '\r';
-                               stream->priv->buffer[1] = '\0';
-                               stream->priv->buflen = 1;
+                               stream->buffer = g_new (gchar, 2);
+                               stream->buffer[0] = '\r';
+                               stream->buffer[1] = '\0';
+                               stream->buflen = 1;
 
                                /* Decrease also the len so in the check
                                   nvalid == len we get out of this method */
@@ -699,16 +698,16 @@ validate_and_insert (GtkSourceBufferOutputStream *stream,
                if ((len < MAX_UNICHAR_LEN) &&
                    (g_utf8_get_char_validated (buffer, len) == (gunichar)-2))
                {
-                       stream->priv->buffer = g_strndup (end, len);
-                       stream->priv->buflen = len;
+                       stream->buffer = g_strndup (end, len);
+                       stream->buflen = len;
 
                        break;
                }
 
                /* we need the start of the chunk of invalid chars */
-               if (stream->priv->error_offset == -1)
+               if (stream->error_offset == -1)
                {
-                       stream->priv->error_offset = gtk_text_iter_get_offset (&stream->priv->pos);
+                       stream->error_offset = gtk_text_iter_get_offset (&stream->pos);
                }
 
                insert_fallback (stream, buffer);
@@ -725,12 +724,12 @@ remove_trailing_newline (GtkSourceBufferOutputStream *stream)
        GtkTextIter end;
        GtkTextIter start;
 
-       if (stream->priv->source_buffer == NULL)
+       if (stream->source_buffer == NULL)
        {
                return;
        }
 
-       gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (stream->priv->source_buffer), &end);
+       gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (stream->source_buffer), &end);
        start = end;
 
        gtk_text_iter_set_line_offset (&start, 0);
@@ -743,7 +742,7 @@ remove_trailing_newline (GtkSourceBufferOutputStream *stream)
                        gtk_text_iter_forward_to_line_end (&start);
                }
 
-               gtk_text_buffer_delete (GTK_TEXT_BUFFER (stream->priv->source_buffer),
+               gtk_text_buffer_delete (GTK_TEXT_BUFFER (stream->source_buffer),
                                        &start,
                                        &end);
        }
@@ -752,30 +751,30 @@ remove_trailing_newline (GtkSourceBufferOutputStream *stream)
 static void
 end_append_text_to_document (GtkSourceBufferOutputStream *stream)
 {
-       if (stream->priv->source_buffer == NULL)
+       if (stream->source_buffer == NULL)
        {
                return;
        }
 
-       if (stream->priv->remove_trailing_newline)
+       if (stream->remove_trailing_newline)
        {
                remove_trailing_newline (stream);
        }
 
-       gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->priv->source_buffer),
+       gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->source_buffer),
                                      FALSE);
 
-       gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (stream->priv->source_buffer));
-       gtk_source_buffer_end_not_undoable_action (stream->priv->source_buffer);
+       gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (stream->source_buffer));
+       gtk_source_buffer_end_not_undoable_action (stream->source_buffer);
 }
 
 static gboolean
 convert_text (GtkSourceBufferOutputStream  *stream,
-             const gchar                  *inbuf,
-             gsize                         inbuf_len,
-             gchar                       **outbuf,
-             gsize                        *outbuf_len,
-             GError                      **error)
+              const gchar                  *inbuf,
+              gsize                         inbuf_len,
+              gchar                       **outbuf,
+              gsize                        *outbuf_len,
+              GError                      **error)
 {
        gchar *out, *dest;
        gsize in_left, out_left, outbuf_size, res;
@@ -800,7 +799,7 @@ convert_text (GtkSourceBufferOutputStream  *stream,
                /* If we reached here is because we need to convert the text,
                   so we convert it using iconv.
                   See that if inbuf is NULL the data will be flushed */
-               res = g_iconv (stream->priv->iconv,
+               res = g_iconv (stream->iconv,
                               (gchar **)&inbuf, &in_left,
                               &out, &out_left);
 
@@ -813,8 +812,8 @@ convert_text (GtkSourceBufferOutputStream  *stream,
                        {
                                case EINVAL:
                                        /* Incomplete text, do not report an error */
-                                       stream->priv->iconv_buffer = g_strndup (inbuf, in_left);
-                                       stream->priv->iconv_buflen = in_left;
+                                       stream->iconv_buffer = g_strndup (inbuf, in_left);
+                                       stream->iconv_buflen = in_left;
                                        done = TRUE;
                                        break;
 
@@ -873,10 +872,10 @@ convert_text (GtkSourceBufferOutputStream  *stream,
 
 static gssize
 gtk_source_buffer_output_stream_write (GOutputStream  *stream,
-                                      const void     *buffer,
-                                      gsize           count,
-                                      GCancellable   *cancellable,
-                                      GError        **error)
+                                       const void     *buffer,
+                                       gsize           count,
+                                       GCancellable   *cancellable,
+                                       GError        **error)
 {
        GtkSourceBufferOutputStream *ostream;
        gchar *text;
@@ -886,19 +885,19 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
        ostream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (stream);
 
        if (g_cancellable_set_error_if_cancelled (cancellable, error) ||
-           ostream->priv->source_buffer == NULL)
+           ostream->source_buffer == NULL)
        {
                return -1;
        }
 
-       if (!ostream->priv->is_initialized)
+       if (!ostream->is_initialized)
        {
-               ostream->priv->charset_conv = guess_encoding (ostream, buffer, count);
+               ostream->charset_conv = guess_encoding (ostream, buffer, count);
 
                /* If we still have the previous case is that we didn't guess
                   anything */
-               if (ostream->priv->charset_conv == NULL &&
-                   !ostream->priv->is_utf8)
+               if (ostream->charset_conv == NULL &&
+                   !ostream->is_utf8)
                {
                        g_set_error_literal (error, GTK_SOURCE_FILE_LOADER_ERROR,
                                             GTK_SOURCE_FILE_LOADER_ERROR_ENCODING_AUTO_DETECTION_FAILED,
@@ -908,18 +907,18 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
                }
 
                /* Do not initialize iconv if we are not going to convert anything */
-               if (!ostream->priv->is_utf8)
+               if (!ostream->is_utf8)
                {
                        gchar *from_charset;
 
                        /* Initialize iconv */
-                       g_object_get (G_OBJECT (ostream->priv->charset_conv),
+                       g_object_get (G_OBJECT (ostream->charset_conv),
                                      "from-charset", &from_charset,
                                      NULL);
 
-                       ostream->priv->iconv = g_iconv_open ("UTF-8", from_charset);
+                       ostream->iconv = g_iconv_open ("UTF-8", from_charset);
 
-                       if (ostream->priv->iconv == (GIConv)-1)
+                       if (ostream->iconv == (GIConv)-1)
                        {
                                if (errno == EINVAL)
                                {
@@ -935,7 +934,7 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
                                }
 
                                g_free (from_charset);
-                               g_clear_object (&ostream->priv->charset_conv);
+                               g_clear_object (&ostream->charset_conv);
 
                                return -1;
                        }
@@ -948,29 +947,29 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
                 * as only one action, for the features that rely on the user
                 * action.
                 */
-               gtk_source_buffer_begin_not_undoable_action (ostream->priv->source_buffer);
-               gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (ostream->priv->source_buffer));
+               gtk_source_buffer_begin_not_undoable_action (ostream->source_buffer);
+               gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (ostream->source_buffer));
 
-               gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (ostream->priv->source_buffer),
-                                               &ostream->priv->pos);
+               gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (ostream->source_buffer),
+                                               &ostream->pos);
 
-               ostream->priv->is_initialized = TRUE;
+               ostream->is_initialized = TRUE;
        }
 
-       if (ostream->priv->buflen > 0)
+       if (ostream->buflen > 0)
        {
-               len = ostream->priv->buflen + count;
+               len = ostream->buflen + count;
                text = g_malloc (len + 1);
 
-               memcpy (text, ostream->priv->buffer, ostream->priv->buflen);
-               memcpy (text + ostream->priv->buflen, buffer, count);
+               memcpy (text, ostream->buffer, ostream->buflen);
+               memcpy (text + ostream->buflen, buffer, count);
 
                text[len] = '\0';
 
-               g_free (ostream->priv->buffer);
+               g_free (ostream->buffer);
 
-               ostream->priv->buffer = NULL;
-               ostream->priv->buflen = 0;
+               ostream->buffer = NULL;
+               ostream->buflen = 0;
 
                freetext = TRUE;
        }
@@ -980,14 +979,14 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
                len = count;
        }
 
-       if (!ostream->priv->is_utf8)
+       if (!ostream->is_utf8)
        {
                gchar *outbuf;
                gsize outbuf_len;
 
                /* check if iconv was correctly initializated, this shouldn't
                   happen but better be safe */
-               if (ostream->priv->iconv == NULL)
+               if (ostream->iconv == NULL)
                {
                        g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_INITIALIZED,
                                             _("Invalid object, not initialized"));
@@ -1001,16 +1000,16 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
                }
 
                /* manage the previous conversion buffer */
-               if (ostream->priv->iconv_buflen > 0)
+               if (ostream->iconv_buflen > 0)
                {
                        gchar *text2;
                        gsize len2;
 
-                       len2 = len + ostream->priv->iconv_buflen;
+                       len2 = len + ostream->iconv_buflen;
                        text2 = g_malloc (len2 + 1);
 
-                       memcpy (text2, ostream->priv->iconv_buffer, ostream->priv->iconv_buflen);
-                       memcpy (text2 + ostream->priv->iconv_buflen, text, len);
+                       memcpy (text2, ostream->iconv_buffer, ostream->iconv_buflen);
+                       memcpy (text2 + ostream->iconv_buflen, text, len);
 
                        text2[len2] = '\0';
 
@@ -1022,10 +1021,10 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
                        text = text2;
                        len = len2;
 
-                       g_free (ostream->priv->iconv_buffer);
+                       g_free (ostream->iconv_buffer);
 
-                       ostream->priv->iconv_buffer = NULL;
-                       ostream->priv->iconv_buflen = 0;
+                       ostream->iconv_buffer = NULL;
+                       ostream->iconv_buflen = 0;
 
                        freetext = TRUE;
                }
@@ -1062,21 +1061,21 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
 
 static gboolean
 gtk_source_buffer_output_stream_flush (GOutputStream  *stream,
-                                      GCancellable   *cancellable,
-                                      GError        **error)
+                                       GCancellable   *cancellable,
+                                       GError        **error)
 {
        GtkSourceBufferOutputStream *ostream;
 
        ostream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (stream);
 
-       if (ostream->priv->is_closed ||
-           ostream->priv->source_buffer == NULL)
+       if (ostream->is_closed ||
+           ostream->source_buffer == NULL)
        {
                return TRUE;
        }
 
        /* if we have converted something flush residual data, validate and insert */
-       if (ostream->priv->iconv != NULL)
+       if (ostream->iconv != NULL)
        {
                gchar *outbuf;
                gsize outbuf_len;
@@ -1092,65 +1091,65 @@ gtk_source_buffer_output_stream_flush (GOutputStream  *stream,
                }
        }
 
-       if (ostream->priv->buflen > 0 && *ostream->priv->buffer != '\r')
+       if (ostream->buflen > 0 && *ostream->buffer != '\r')
        {
                /* If we reached here is because the last insertion was a half
                   correct char, which has to be inserted as fallback */
                gchar *text;
 
-               if (ostream->priv->error_offset == -1)
+               if (ostream->error_offset == -1)
                {
-                       ostream->priv->error_offset = gtk_text_iter_get_offset (&ostream->priv->pos);
+                       ostream->error_offset = gtk_text_iter_get_offset (&ostream->pos);
                }
 
-               text = ostream->priv->buffer;
-               while (ostream->priv->buflen != 0)
+               text = ostream->buffer;
+               while (ostream->buflen != 0)
                {
                        insert_fallback (ostream, text);
                        ++text;
-                       --ostream->priv->buflen;
+                       --ostream->buflen;
                }
 
-               g_free (ostream->priv->buffer);
-               ostream->priv->buffer = NULL;
+               g_free (ostream->buffer);
+               ostream->buffer = NULL;
        }
-       else if (ostream->priv->buflen == 1 && *ostream->priv->buffer == '\r')
+       else if (ostream->buflen == 1 && *ostream->buffer == '\r')
        {
                /* The previous chars can be invalid */
                apply_error_tag (ostream);
 
                /* See special case above, flush this */
-               gtk_text_buffer_insert (GTK_TEXT_BUFFER (ostream->priv->source_buffer),
-                                       &ostream->priv->pos,
+               gtk_text_buffer_insert (GTK_TEXT_BUFFER (ostream->source_buffer),
+                                       &ostream->pos,
                                        "\r",
                                        1);
 
-               g_free (ostream->priv->buffer);
-               ostream->priv->buffer = NULL;
-               ostream->priv->buflen = 0;
+               g_free (ostream->buffer);
+               ostream->buffer = NULL;
+               ostream->buflen = 0;
        }
 
-       if (ostream->priv->iconv_buflen > 0 )
+       if (ostream->iconv_buflen > 0 )
        {
                /* If we reached here is because the last insertion was a half
                   correct char, which has to be inserted as fallback */
                gchar *text;
 
-               if (ostream->priv->error_offset == -1)
+               if (ostream->error_offset == -1)
                {
-                       ostream->priv->error_offset = gtk_text_iter_get_offset (&ostream->priv->pos);
+                       ostream->error_offset = gtk_text_iter_get_offset (&ostream->pos);
                }
 
-               text = ostream->priv->iconv_buffer;
-               while (ostream->priv->iconv_buflen != 0)
+               text = ostream->iconv_buffer;
+               while (ostream->iconv_buflen != 0)
                {
                        insert_fallback (ostream, text);
                        ++text;
-                       --ostream->priv->iconv_buflen;
+                       --ostream->iconv_buflen;
                }
 
-               g_free (ostream->priv->iconv_buffer);
-               ostream->priv->iconv_buffer = NULL;
+               g_free (ostream->iconv_buffer);
+               ostream->iconv_buffer = NULL;
        }
 
        apply_error_tag (ostream);
@@ -1160,24 +1159,24 @@ gtk_source_buffer_output_stream_flush (GOutputStream  *stream,
 
 static gboolean
 gtk_source_buffer_output_stream_close (GOutputStream  *stream,
-                                      GCancellable   *cancellable,
-                                      GError        **error)
+                                       GCancellable   *cancellable,
+                                       GError        **error)
 {
        GtkSourceBufferOutputStream *ostream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (stream);
 
-       if (!ostream->priv->is_closed && ostream->priv->is_initialized)
+       if (!ostream->is_closed && ostream->is_initialized)
        {
                end_append_text_to_document (ostream);
 
-               if (ostream->priv->iconv != NULL)
+               if (ostream->iconv != NULL)
                {
-                       g_iconv_close (ostream->priv->iconv);
+                       g_iconv_close (ostream->iconv);
                }
 
-               ostream->priv->is_closed = TRUE;
+               ostream->is_closed = TRUE;
        }
 
-       if (ostream->priv->buflen > 0 || ostream->priv->iconv_buflen > 0)
+       if (ostream->buflen > 0 || ostream->iconv_buflen > 0)
        {
                g_set_error (error,
                             G_IO_ERROR,
diff --git a/gtksourceview/gtksourcefileloader.c b/gtksourceview/gtksourcefileloader.c
index 2d1256f9..e6970fe2 100644
--- a/gtksourceview/gtksourcefileloader.c
+++ b/gtksourceview/gtksourcefileloader.c
@@ -28,7 +28,7 @@
 #include "gtksourcefileloader.h"
 #include "gtksourcebuffer.h"
 #include "gtksourcefile-private.h"
-#include "gtksourcebufferoutputstream.h"
+#include "gtksourcebufferoutputstream-private.h"
 #include "gtksourceencoding.h"
 #include "gtksourceencoding-private.h"
 #include "gtksource-enumtypes.h"
diff --git a/testsuite/test-buffer-output-stream.c b/testsuite/test-buffer-output-stream.c
index c844093d..aae085f8 100644
--- a/testsuite/test-buffer-output-stream.c
+++ b/testsuite/test-buffer-output-stream.c
@@ -24,13 +24,13 @@
 #include <gtk/gtk.h>
 #include <string.h>
 #include <gtksourceview/gtksource.h>
-#include "gtksourceview/gtksourcebufferoutputstream.h"
+#include "gtksourceview/gtksourcebufferoutputstream-private.h"
 
 static void
 test_consecutive_write (const gchar          *inbuf,
-                       const gchar          *outbuf,
-                       gsize                 write_chunk_len,
-                       GtkSourceNewlineType  newline_type)
+                        const gchar          *outbuf,
+                        gsize                 write_chunk_len,
+                        GtkSourceNewlineType  newline_type)
 {
        GtkSourceBuffer *source_buffer;
        GtkSourceBufferOutputStream *out;
@@ -166,11 +166,11 @@ test_invalid_utf8 (void)
 
 static gchar *
 get_encoded_text (const gchar             *text,
-                 gint                     nread,
-                 const GtkSourceEncoding *to,
-                 const GtkSourceEncoding *from,
-                 gsize                   *bytes_written_aux,
-                 gboolean                 care_about_error)
+                  gint                     nread,
+                  const GtkSourceEncoding *to,
+                  const GtkSourceEncoding *from,
+                  gsize                   *bytes_written_aux,
+                  gboolean                 care_about_error)
 {
        GCharsetConverter *converter;
        gchar *out, *out_aux;
@@ -240,11 +240,11 @@ get_encoded_text (const gchar             *text,
 
 static gchar *
 do_test (const gchar              *inbuf,
-        const gchar              *enc,
-        GSList                   *encodings,
-        gsize                     len,
-        gsize                     write_chunk_len,
-        const GtkSourceEncoding **guessed)
+         const gchar              *enc,
+         GSList                   *encodings,
+         gsize                     len,
+         gsize                     write_chunk_len,
+         const GtkSourceEncoding **guessed)
 {
        GtkSourceBuffer *source_buffer;
        GtkSourceBufferOutputStream *out;


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