From a1fa82f65eceddd76861ce132c8b1b9a458eb0de Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Fri, 29 Sep 2017 17:04:37 -0400 Subject: src/about.c: Use strtok_r() to parse query strings This may be a bit slower with function overhead etc., but it's much less code and much more readable. --- (limited to 'src/about.c') diff --git a/src/about.c b/src/about.c index e21fa9e..26ea0a7 100644 --- a/src/about.c +++ b/src/about.c @@ -19,6 +19,8 @@ * along with Marquee. If not, see . */ +#define _POSIX_C_SOURCE 200809L + #include #include @@ -31,28 +33,18 @@ GHashTable * parse_query_string(gchar *str) { GHashTable *hash_table; + gboolean first; + gchar *saveptr; gchar *key; gchar *val; hash_table = g_hash_table_new(g_str_hash, g_str_equal); - while (*str) { - key = str; - for (; *str && *str != '='; ++str); - if (!*str) { - g_hash_table_insert(hash_table, key, NULL); - break; - } - *str = '\0'; - val = ++str; - for (; *str && *str != '&'; ++str); - if (!*str) { - g_hash_table_insert(hash_table, key, val); - break; - } - *str = '\0'; + first = TRUE; + while ((key = strtok_r(first ? str : NULL, "=", &saveptr))) { + first = FALSE; + val = strtok_r(NULL, "&", &saveptr); g_hash_table_insert(hash_table, key, val); - ++str; } return hash_table; -- cgit v0.9.1