summaryrefslogtreecommitdiff
path: root/src/shortcut.c
diff options
context:
space:
mode:
authorDaniel Carl <danielcarl@gmx.de>2013-05-05 13:58:31 +0200
committerDaniel Carl <danielcarl@gmx.de>2013-05-05 13:58:31 +0200
commitee19f17849f6526556e7d717f16b48e6066c55cd (patch)
tree716d06048d4f21e72ff227b5766197f51031852d /src/shortcut.c
parent08c8c7730ec62a4d09d8889caa549367eaca4294 (diff)
Simplified the shortcut system.
Don't treat the $0 with a special meaning to be filled by the whole query string. Instead split the query string into as many parts like the highest available placeholder + 1. That means if only $0 is used in a shortcut this will also be replaced by the whole query string, but it could also be only the first parameter in the case when the shortcut contains also other placeholders.
Diffstat (limited to 'src/shortcut.c')
-rw-r--r--src/shortcut.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/shortcut.c b/src/shortcut.c
index 7d53b1a..02d194b 100644
--- a/src/shortcut.c
+++ b/src/shortcut.c
@@ -70,21 +70,17 @@ gboolean shortcut_set_default(const char *key)
char *shortcut_get_uri(const char *string)
{
const char *tmpl, *query = NULL;
+ char *uri, **parts, ph[3] = "$0";
+ unsigned int len;
+ int max;
tmpl = shortcut_lookup(string, &query);
if (!tmpl) {
return NULL;
}
- char *qs, *uri, **parts, ph[3] = "$0";
- unsigned int len;
-
- /* replace $0 with all parameters */
- qs = soup_uri_encode(query, "&");
- uri = util_str_replace(ph, qs, tmpl);
- g_free(qs);
-
- int max = get_max_placeholder(tmpl);
+ uri = g_strdup(tmpl);
+ max = get_max_placeholder(tmpl);
/* skip if no placeholders found */
if (max < 0) {
return uri;
@@ -95,8 +91,8 @@ char *shortcut_get_uri(const char *string)
len = g_strv_length(parts);
for (unsigned int n = 0; n < len; n++) {
- char *new;
- ph[1] = n + '1';
+ char *new, *qs;
+ ph[1] = n + '0';
qs = soup_uri_encode(parts[n], "&");
new = util_str_replace(ph, qs, uri);
g_free(qs);