[gnome-terminal/wip/rishi/use-g-utf8-make-valid] util: Use GLib for coercing UTF-8 in hyperlink tooltips



commit c46d004f1d1c69f22e99b4629d5bd2508b2f2904
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Mar 3 21:22:17 2020 +0100

    util: Use GLib for coercing UTF-8 in hyperlink tooltips
    
    GLib 2.52.0 was released in March 2017 and is present in even RHEL 7.x.
    It's clearly old enough for to be a hard dependency.
    
    https://gitlab.gnome.org/GNOME/gnome-terminal/issues/226

 configure.ac        |  6 +++---
 src/terminal-util.c | 55 +----------------------------------------------------
 src/terminal-util.h |  3 ---
 3 files changed, 4 insertions(+), 60 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8cc1caf5..b0fc75cc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,9 +37,9 @@ AM_GNU_GETTEXT([external])
 
 AX_PTHREAD([],[AC_MSG_ERROR([pthreads are required])])
 
-GLIB_REQUIRED=2.50.0
-GLIB_MIN_REQUIRED=2.50
-GLIB_MAX_ALLOWED=2.50
+GLIB_REQUIRED=2.52.0
+GLIB_MIN_REQUIRED=2.52
+GLIB_MAX_ALLOWED=2.52
 
 GIO_REQUIRED=2.34.0
 GIO_UNIX_REQUIRED=2.34.0
diff --git a/src/terminal-util.c b/src/terminal-util.c
index a854e9cf..128d4da8 100644
--- a/src/terminal-util.c
+++ b/src/terminal-util.c
@@ -1206,60 +1206,7 @@ char *terminal_util_hyperlink_uri_label (const char *uri)
     }
   }
 
-  return terminal_util_utf8_make_valid (unesc, -1);
-}
-
-/**
- * terminal_util_utf8_make_valid:
- *
- * Just as g_utf8_make_valid().
- *
- * FIXME: Use g_utf8_make_valid() instead once we require glib >= 2.52.
- */
-gchar *
-terminal_util_utf8_make_valid (const gchar *str,
-                               gssize       len)
-{
-  /* copied from glib's g_utf8_make_valid() implementation */
-  GString *string;
-  const gchar *remainder, *invalid;
-  gsize remaining_bytes, valid_bytes;
-
-  g_return_val_if_fail (str != NULL, NULL);
-
-  if (len < 0)
-    len = strlen (str);
-
-  string = NULL;
-  remainder = str;
-  remaining_bytes = len;
-
-  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_strndup (str, len);
-
-  g_string_append_len (string, remainder, remaining_bytes);
-  g_string_append_c (string, '\0');
-
-  g_assert (g_utf8_validate (string->str, -1, NULL));
-
-  return g_string_free (string, FALSE);
+  return g_utf8_make_valid (unesc, -1);
 }
 
 #define TERMINAL_CACHE_DIR                 "gnome-terminal"
diff --git a/src/terminal-util.h b/src/terminal-util.h
index a8a75475..85784410 100644
--- a/src/terminal-util.h
+++ b/src/terminal-util.h
@@ -99,9 +99,6 @@ char *terminal_util_uri_fixup (const char *uri,
 
 char *terminal_util_hyperlink_uri_label (const char *str);
 
-gchar *terminal_util_utf8_make_valid (const gchar *str,
-                                      gssize       len) G_GNUC_MALLOC;
-
 void terminal_util_load_print_settings (GtkPrintSettings **settings,
                                         GtkPageSetup **page_setup);
 


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