[gthumb] string util: added function to split a string as hash table keys



commit 6bcedb3f72c365491abf89526f760da4c9836b1e
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sat Mar 7 18:29:46 2020 +0100

    string util: added function to split a string as hash table keys

 gthumb/str-utils.c | 23 +++++++++++++++++++++++
 gthumb/str-utils.h |  2 ++
 2 files changed, 25 insertions(+)
---
diff --git a/gthumb/str-utils.c b/gthumb/str-utils.c
index b7c8200c..a431ac73 100644
--- a/gthumb/str-utils.c
+++ b/gthumb/str-utils.c
@@ -167,6 +167,29 @@ _g_str_get_static (const char *str)
 }
 
 
+GHashTable *
+_g_str_split_as_hash_table (const char *str)
+{
+       GHashTable *htable;
+
+       htable = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+
+       if (str != NULL) {
+               char **strv;
+               int    i;
+
+               strv = g_strsplit (str, ",", -1);
+               for (i = 0; strv[i] != NULL; i++)
+                       if (strv[i] != 0)
+                               g_hash_table_add (htable, g_strdup (strv[i]));
+
+               g_strfreev (strv);
+       }
+
+       return htable;
+}
+
+
 /* StrV utils */
 
 
diff --git a/gthumb/str-utils.h b/gthumb/str-utils.h
index d5156152..0f91d7c1 100644
--- a/gthumb/str-utils.h
+++ b/gthumb/str-utils.h
@@ -42,6 +42,8 @@ char *                _g_str_random           (int              len);
 char *         _g_str_remove_suffix    (const char      *str,
                                         const char      *suffix);
 const char *   _g_str_get_static       (const char      *str);
+GHashTable *   _g_str_split_as_hash_table
+                                       (const char      *str);
 
 /* StrV utils */
 


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