diff options
author | Phillip Wood <phillip.wood@dunelm.org.uk> | 2012-05-05 14:18:56 +0100 |
---|---|---|
committer | Christophe Fergeau <cfergeau@redhat.com> | 2012-09-06 19:58:37 +0200 |
commit | b59383adfad80621a20f30b33f36dc2e37f846da (patch) | |
tree | 73939a917d1505345d2af5d66202613a5456d12a /libjuicer | |
parent | f9166222147fae308b6beebe7fc6bdc8b22f401e (diff) |
Add sj_str_is_empty (const char *s)
utility function to test if string is NULL, NUL or just ascii space.
https://bugzilla.gnome.org/show_bug.cgi?id=661646
Diffstat (limited to 'libjuicer')
-rw-r--r-- | libjuicer/sj-util.c | 16 | ||||
-rw-r--r-- | libjuicer/sj-util.h | 2 |
2 files changed, 17 insertions, 1 deletions
diff --git a/libjuicer/sj-util.c b/libjuicer/sj-util.c index ea02355..1d4d9f9 100644 --- a/libjuicer/sj-util.c +++ b/libjuicer/sj-util.c @@ -120,3 +120,19 @@ sj_add_default_dirs (GtkFileChooser *dialog) } } +/* + * True if string is NULL, empty or contains only ascii space + */ +gboolean +sj_str_is_empty (const char *s) +{ + int i = 0; + + if (s == NULL) + return TRUE; + while (s[i]) { + if (!g_ascii_isspace (s[i++])) + return FALSE; + } + return TRUE; +} diff --git a/libjuicer/sj-util.h b/libjuicer/sj-util.h index 5335d2b..2ed24e5 100644 --- a/libjuicer/sj-util.h +++ b/libjuicer/sj-util.h @@ -33,5 +33,5 @@ void g_list_deep_free (GList *l, GFunc free_func); void sj_add_default_dirs (GtkFileChooser *dialog); GFile *sj_get_default_music_directory (void); - +gboolean sj_str_is_empty (const char *s); #endif /* SJ_UTIL_H */ |