[epiphany/gnome-3-36] output-encoding: fix build with older GLib



commit 25e6d1c57a6002b081f6f225e5abd953fbe13768
Author: Michael Catanzaro <mcatanzaro redhat com>
Date:   Tue Feb 8 14:39:09 2022 -0600

    output-encoding: fix build with older GLib

 lib/ephy-output-encoding.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
---
diff --git a/lib/ephy-output-encoding.c b/lib/ephy-output-encoding.c
index 2a7c1d0a8..1263b25e8 100644
--- a/lib/ephy-output-encoding.c
+++ b/lib/ephy-output-encoding.c
@@ -23,6 +23,49 @@
 
 #include <glib.h>
 
+#if !GLIB_CHECK_VERSION(2, 68, 0)
+static guint
+g_string_replace (GString     *string,
+                  const gchar *find,
+                  const gchar *replace,
+                  guint        limit)
+{
+  gsize f_len, r_len, pos;
+  gchar *cur, *next;
+  guint n = 0;
+
+  g_return_val_if_fail (string != NULL, 0);
+  g_return_val_if_fail (find != NULL, 0);
+  g_return_val_if_fail (replace != NULL, 0);
+
+  f_len = strlen (find);
+  r_len = strlen (replace);
+  cur = string->str;
+
+  while ((next = strstr (cur, find)) != NULL)
+    {
+      pos = next - string->str;
+      g_string_erase (string, pos, f_len);
+      g_string_insert (string, pos, replace);
+      cur = string->str + pos + r_len;
+      n++;
+      /* Only match the empty string once at any given position, to
+       * avoid infinite loops */
+      if (f_len == 0)
+        {
+          if (cur[0] == '\0')
+            break;
+          else
+            cur++;
+        }
+      if (n == limit)
+        break;
+    }
+
+  return n;
+}
+#endif
+
 char *
 ephy_encode_for_html_entity (const char *input)
 {


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