2
0
Fork 0

[core] Add li_querystring_find() function to utils

personal/stbuehler/wip
Thomas Porzelt 2009-08-13 18:38:30 +02:00
parent f0d5c9e789
commit 86ebb4c7f0
2 changed files with 38 additions and 0 deletions

View File

@ -41,6 +41,9 @@ LI_API void li_url_decode(GString *path);
LI_API void li_path_simplify(GString *path);
/* finds the first value for a given key in the querystring. works with '&' as well as ';' delimiters */
LI_API gboolean li_querystring_find(GString *querystring, const gchar *key, const guint key_len, gchar **val, guint *val_len);
/* formats a given guint64 for output. if dest is NULL, a new string is allocated */
LI_API GString *li_counter_format(guint64 count, liCounterType t, GString *dest);

View File

@ -374,6 +374,41 @@ void li_path_simplify(GString *path) {
}
gboolean li_querystring_find(GString *querystring, const gchar *key, const guint key_len, gchar **val, guint *val_len) {
gchar delim = '\0';
gchar *end = querystring->str + querystring->len;
gchar *start = querystring->str;
gchar *c = querystring->str;
/* search for key */
for (c = querystring->str; c != end; c++) {
if ((*c == '&' || *c == ';') && delim == '\0')
delim = *c;
if (*c == '=' || (*c == delim && delim != '\0')) {
if ((c - start) == (gint)key_len && memcmp(start, key, key_len) == 0) {
/* key found */
c++;
*val = c;
/* get length of val */
for (; c != end; c++) {
if ((*c == '&' || *c == ';') && (delim == '\0' || *c == delim))
break;
}
*val_len = c - *val;
return TRUE;
}
start = c + 1;
}
}
return FALSE;
}
GString *li_counter_format(guint64 count, liCounterType t, GString *dest) {
guint64 rest;