diff options
author | Stefano Karapetsas <[email protected]> | 2012-11-05 14:08:40 -0800 |
---|---|---|
committer | Stefano Karapetsas <[email protected]> | 2012-11-05 14:08:40 -0800 |
commit | 0d97b91e417fda108955b155cc287db086850c81 (patch) | |
tree | 5fd33bf86621b0de3aa2cb30b7b940f74c979749 /src/glib-utils.c | |
parent | 8f8784ba4ebcd8eb099c4e119a9a8d5a349efd61 (diff) | |
parent | 61fe44bd16be34d89b127f403b3e07d63aa67e89 (diff) | |
download | engrampa-0d97b91e417fda108955b155cc287db086850c81.tar.bz2 engrampa-0d97b91e417fda108955b155cc287db086850c81.tar.xz |
Merge pull request #7 from NiceandGently/master
port to gsettings
Diffstat (limited to 'src/glib-utils.c')
-rw-r--r-- | src/glib-utils.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/glib-utils.c b/src/glib-utils.c index a484fcf..176370c 100644 --- a/src/glib-utils.c +++ b/src/glib-utils.c @@ -25,12 +25,36 @@ #include <glib.h> #include <glib/gi18n.h> #include <glib/gprintf.h> +#include <glib-object.h> #include "glib-utils.h" #define MAX_PATTERNS 128 +/* gobject utils*/ + + +gpointer +_g_object_ref (gpointer object) +{ + if (object != NULL) + return g_object_ref (object); + else + return NULL; +} + + +void +_g_object_unref (gpointer object) +{ + if (object != NULL) + g_object_unref (object); +} + + +/* string utils */ + gboolean strchrs (const char *str, const char *chars) @@ -643,3 +667,47 @@ g_uri_display_basename (const char *uri) return name; } + + +char ** +_g_strv_prepend (char **str_array, + const char *str) +{ + char **result; + int i; + int j; + + result = g_new (char *, g_strv_length (str_array) + 1); + i = 0; + result[i++] = g_strdup (str); + for (j = 0; str_array[j] != NULL; j++) + result[i++] = g_strdup (str_array[j]); + result[i] = NULL; + + return result; +} + + +gboolean +_g_strv_remove (char **str_array, + const char *str) +{ + int i; + int j; + + if (str == NULL) + return FALSE; + + for (i = 0; str_array[i] != NULL; i++) + if (strcmp (str_array[i], str) == 0) + break; + + if (str_array[i] == NULL) + return FALSE; + + for (j = i; str_array[j] != NULL; j++) + str_array[j] = str_array[j + 1]; + + return TRUE; +} + |