diff options
author | Patrick McDermott <pj@pehjota.net> | 2017-09-29 17:04:37 (EDT) |
---|---|---|
committer | Patrick McDermott <pj@pehjota.net> | 2017-09-29 17:04:37 (EDT) |
commit | a1fa82f65eceddd76861ce132c8b1b9a458eb0de (patch) | |
tree | c59d4022965023b270df8c32e631ab9a519dbd97 | |
parent | a6feec8f22af0266f8003a8d4aeda3fb2adbcab7 (diff) | |
download | marquee-a1fa82f65eceddd76861ce132c8b1b9a458eb0de.zip marquee-a1fa82f65eceddd76861ce132c8b1b9a458eb0de.tar.gz marquee-a1fa82f65eceddd76861ce132c8b1b9a458eb0de.tar.bz2 |
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.
-rw-r--r-- | src/about.c | 24 |
1 files changed, 8 insertions, 16 deletions
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 <http://www.gnu.org/licenses/>. */ +#define _POSIX_C_SOURCE 200809L + #include <string.h> #include <webkit2/webkit2.h> @@ -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; |