about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-01-30 00:48:32 +0000
committerJames Booth <boothj5@gmail.com>2013-01-30 00:48:32 +0000
commit0ef52901c9f8b570705f644956a2337d65cbf7d3 (patch)
tree8693b3d1d8bfe6f6b4c8527cedfdd4d9e0da45bb
parent957bea19e4506eaece5efa974bffc75b99cba318 (diff)
downloadprofani-tty-0ef52901c9f8b570705f644956a2337d65cbf7d3.tar.gz
Added glib < 2.30 compatibility function
-rw-r--r--src/common.c15
-rw-r--r--src/common.h7
2 files changed, 21 insertions, 1 deletions
diff --git a/src/common.c b/src/common.c
index d535ff32..a58be8f2 100644
--- a/src/common.c
+++ b/src/common.c
@@ -43,6 +43,21 @@ struct curl_data_t
 
 static size_t _data_callback(void *ptr, size_t size, size_t nmemb, void *data);
 
+// taken from glib 2.30.3
+gchar *
+p_utf8_substring(const gchar *str, glong start_pos, glong end_pos)
+{
+    gchar *start, *end, *out;
+
+    start = g_utf8_offset_to_pointer (str, start_pos);
+    end = g_utf8_offset_to_pointer (start, end_pos - start_pos);
+
+    out = g_malloc (end - start + 1);
+    memcpy (out, start, end - start);
+    out[end - start] = 0;
+
+    return out;
+}
 
 // backwards compatibility for GLib version < 2.28
 void
diff --git a/src/common.h b/src/common.h
index 075b5d7d..93d59895 100644
--- a/src/common.h
+++ b/src/common.h
@@ -27,7 +27,11 @@
 #include <glib.h>
 
 #if !GLIB_CHECK_VERSION(2,28,0)
-#define g_slist_free_full(items, free_func)      p_slist_free_full(items, free_func)
+#define g_slist_free_full(items, free_func)         p_slist_free_full(items, free_func)
+#endif
+
+#if !GLIB_CHECK_VERSION(2,30,0)
+#define g_utf8_substring(str, start_pos, end_pos)   p_utf8_substring(str, start_pos, end_pos)
 #endif
 
 #ifndef NOTIFY_CHECK_VERSION
@@ -50,6 +54,7 @@
     resource = NULL; \
 }
 
+gchar* p_utf8_substring(const gchar *str, glong start_pos, glong end_pos);
 void p_slist_free_full(GSList *items, GDestroyNotify free_func);
 void create_dir(char *name);
 char * str_replace(const char *string, const char *substr,