[gedit] Revert "Utils: deprecate make_valid_utf8(), use g_utf8_make_valid()"



commit adce81a236ae2a446f7bb59d6a22d56811f53189
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Wed Nov 6 13:02:44 2019 -0600

    Revert "Utils: deprecate make_valid_utf8(), use g_utf8_make_valid()"
    
    This reverts commit 50053bf27f627c8d134bc0ebbfd7ec98b96d0543.

 gedit/gedit-utils.c | 47 +++++++++++++++++++++++++++++++++++++++--------
 gedit/gedit-utils.h |  1 -
 meson.build         |  2 +-
 3 files changed, 40 insertions(+), 10 deletions(-)
---
diff --git a/gedit/gedit-utils.c b/gedit/gedit-utils.c
index defb565e7..58adac0f3 100644
--- a/gedit/gedit-utils.c
+++ b/gedit/gedit-utils.c
@@ -245,17 +245,48 @@ gedit_utils_str_end_truncate (const gchar *string,
        return tepl_utils_str_end_truncate (string, truncate_length);
 }
 
-/**
- * gedit_utils_make_valid_utf8:
- * @name:
- *
- * Returns:
- * Deprecated: 3.36: Use g_utf8_make_valid() instead.
- */
 gchar *
 gedit_utils_make_valid_utf8 (const char *name)
 {
-       return g_utf8_make_valid (name, -1);
+       GString *string;
+       const char *remainder, *invalid;
+       int remaining_bytes, valid_bytes;
+
+       g_return_val_if_fail (name != NULL, NULL);
+
+       string = NULL;
+       remainder = name;
+       remaining_bytes = strlen (name);
+
+       while (remaining_bytes != 0) {
+               if (g_utf8_validate (remainder, remaining_bytes, &invalid))
+               {
+                       break;
+               }
+               valid_bytes = invalid - remainder;
+
+               if (string == NULL)
+               {
+                       string = g_string_sized_new (remaining_bytes);
+               }
+               g_string_append_len (string, remainder, valid_bytes);
+               /* append U+FFFD REPLACEMENT CHARACTER */
+               g_string_append (string, "\357\277\275");
+
+               remaining_bytes -= valid_bytes + 1;
+               remainder = invalid + 1;
+       }
+
+       if (string == NULL)
+       {
+               return g_strdup (name);
+       }
+
+       g_string_append (string, remainder);
+
+       g_assert (g_utf8_validate (string->str, -1, NULL));
+
+       return g_string_free (string, FALSE);
 }
 
 static gchar *
diff --git a/gedit/gedit-utils.h b/gedit/gedit-utils.h
index 32f97e57e..ab8456f99 100644
--- a/gedit/gedit-utils.h
+++ b/gedit/gedit-utils.h
@@ -66,7 +66,6 @@ void                       gedit_utils_set_atk_relation                       (G
 void                       gedit_warning                                       (GtkWindow      *parent,
                                                                                 const gchar    *format,
                                                                                 ...) G_GNUC_PRINTF(2, 3);
-G_DEPRECATED_FOR (g_utf8_make_valid)
 gchar                     *gedit_utils_make_valid_utf8                         (const char     *name);
 
 
diff --git a/meson.build b/meson.build
index c62271637..ddb591e60 100644
--- a/meson.build
+++ b/meson.build
@@ -60,7 +60,7 @@ libgd_sp = subproject(
 )
 
 # Dependencies
-glib_req = '>= 2.52'
+glib_req = '>= 2.44.0'
 gtk_req = '>= 3.22.0'
 gtksourceview_req = '>= 4.0.2'
 tepl_req = '>= 4.3'


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