diff options
-rw-r--r-- | src/string-utils.c | 37 | ||||
-rw-r--r-- | src/string-utils.h | 3 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/string-utils.c b/src/string-utils.c index 96b5a0e..8484468 100644 --- a/src/string-utils.c +++ b/src/string-utils.c @@ -35,3 +35,40 @@ atoi64(const gchar *a) return 0; } } + +GHashTable * +parse_query_string(gchar *str) +{ + GHashTable *hash_table; + gchar *key; + gchar *val; + + hash_table = g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, g_free); + + while (*str) { + key = str; + for (; *str && *str != '='; ++str); + if (!*str) { + g_hash_table_insert(hash_table, + g_uri_unescape_string(key, NULL), NULL); + break; + } + *str = '\0'; + val = ++str; + for (; *str && *str != '&'; ++str); + if (!*str) { + g_hash_table_insert(hash_table, + g_uri_unescape_string(key, NULL), + g_uri_unescape_string(val, NULL)); + break; + } + *str = '\0'; + g_hash_table_insert(hash_table, + g_uri_unescape_string(key, NULL), + g_uri_unescape_string(val, NULL)); + ++str; + } + + return hash_table; +} diff --git a/src/string-utils.h b/src/string-utils.h index 5ea48ee..6e9c31c 100644 --- a/src/string-utils.h +++ b/src/string-utils.h @@ -29,6 +29,9 @@ G_BEGIN_DECLS gint64 atoi64(const gchar *a); +GHashTable * +parse_query_string(gchar *str); + G_END_DECLS #endif /* MQ_STRING_UTILITIES_H */ |