diff options
author | Patrick McDermott <pj@pehjota.net> | 2017-10-31 01:26:48 (EDT) |
---|---|---|
committer | Patrick McDermott <pj@pehjota.net> | 2017-10-31 01:26:48 (EDT) |
commit | a2975a2b35a0b1911d1bde716cfe750c31967a2f (patch) | |
tree | 0d3be70d0e427c58263f77cd5ef481463a22ef87 /src | |
parent | 82081a4ec2d8e3ea2d354d5310385ed04d8d43e9 (diff) | |
download | marquee-a2975a2b35a0b1911d1bde716cfe750c31967a2f.zip marquee-a2975a2b35a0b1911d1bde716cfe750c31967a2f.tar.gz marquee-a2975a2b35a0b1911d1bde716cfe750c31967a2f.tar.bz2 |
parse_query_string(): New (public) function
Copied from src/about.c.
Diffstat (limited to 'src')
-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 */ |