This handles the presence of a %1 and encoding the keywords.
new_uri = sokoke_magic_uri (uri, browser->search_engines);
if (!new_uri)
- {
- gchar* uri_ = g_uri_escape_string (uri, " :/", TRUE);
- if (strstr (browser->location_entry_search, "%s"))
- new_uri = g_strdup_printf (browser->location_entry_search, uri_);
- else if (!new_uri)
- new_uri = g_strconcat (browser->location_entry_search, uri_, NULL);
- g_free (uri_);
- }
+ new_uri = sokoke_search_uri (browser->location_entry_search, uri);
if (new_tab)
{
else /* The location entry search is our fallback */
url = browser->location_entry_search;
- if (strstr (url, "%s"))
- search = g_strdup_printf (url, keywords);
- else
- search = g_strconcat (url, " ", keywords, NULL);
+ search = sokoke_search_uri (url, keywords);
if (new_tab)
midori_browser_add_uri (browser, search);
gchar* search;
if (!item)
return;
- if (strstr (uri, "%s"))
- search = g_strdup_printf (uri, keywords);
- else
- search = g_strconcat (uri, " ", keywords, NULL);
+ search = sokoke_search_uri (uri, keywords);
midori_location_action_set_uri (location_action, search);
g_signal_emit (location_action, signals[SUBMIT_URI], 0, search, FALSE);
g_free (search);
else
g_object_get (view->settings, "location-entry-search",
&search, NULL);
- if (strstr (search, "%s"))
- uri = g_strdup_printf (search, view->selected_text);
- else
- uri = g_strconcat (search, view->selected_text, NULL);
+ uri = sokoke_search_uri (search, view->selected_text);
g_free (search);
g_signal_emit (view, signals[NEW_TAB], 0, uri,
#endif
}
+/**
+ * sokoke_search_uri:
+ * @uri: a search URI with or without %s
+ * @keywords: keywords
+ *
+ * Takes a search engine URI and inserts the specified
+ * keywords. The @keywords are percent encoded. If the
+ * search URI contains a %s they keywords are inserted
+ * in that place, otherwise appended to the URI.
+ *
+ * Return value: a newly allocated search URI
+ **/
+gchar* sokoke_search_uri (const gchar* uri,
+ const gchar* keywords)
+{
+ gchar* escaped;
+ gchar* search;
+
+ g_return_val_if_fail (uri != NULL, NULL);
+ g_return_val_if_fail (keywords != NULL, NULL);
+
+ escaped = g_uri_escape_string (keywords, " :/", TRUE);
+ if (strstr (uri, "%s"))
+ search = g_strdup_printf (uri, escaped);
+ else
+ search = g_strconcat (uri, escaped, NULL);
+ g_free (escaped);
+ return search;
+}
+
gchar*
sokoke_magic_uri (const gchar* uri,
KatzeArray* search_engines)
if (parts[0] && parts[1])
if ((item = katze_array_find_token (search_engines, parts[0])))
{
- gchar* uri_ = g_uri_escape_string (parts[1], " :/", TRUE);
search_uri = katze_item_get_uri (item);
- if (strstr (search_uri, "%s"))
- search = g_strdup_printf (search_uri, uri_);
- else
- search = g_strconcat (search_uri, uri_, NULL);
- g_free (uri_);
+ search = sokoke_search_uri (search_uri, parts[1]);
}
g_strfreev (parts);
return search;