From 0ef52901c9f8b570705f644956a2337d65cbf7d3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 30 Jan 2013 00:48:32 +0000 Subject: Added glib < 2.30 compatibility function --- src/common.c | 15 +++++++++++++++ src/common.h | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletion(-) 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 #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, -- cgit 1.4.1-2-gfad0