From 3a78991995ffbd980f1520a4c666929a7ed8b19c Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Tue, 29 Nov 2005 15:09:04 +0000 Subject: Add a method to generate collation keys for domain names. 2005-11-29 Christian Persch * lib/ephy-string.c: (ephy_string_collate_key_for_domain): * lib/ephy-string.h: Add a method to generate collation keys for domain names. * src/pdm-dialog.c: (cookie_search_equal), (pdm_dialog_cookies_construct), (cookie_host_to_iter), (compare_cookie_host_keys), (pdm_dialog_fill_cookies_list), (pdm_dialog_cookies_destruct), (pdm_dialog_cookie_add), (pdm_dialog_cookie_scroll_to), (sync_notebook_tab), (pdm_dialog_init), (pdm_dialog_finalize), (pdm_dialog_open): * src/pdm-dialog.h: * src/window-commands.c: (window_cmd_edit_personal_data): Open the PDM dialogue on the cookies page scrolled to show the cookies of the currently loaded page, if there are any. Sort cookies by domain. Allow treeview typeaheadfind search to find by substring not prefix. --- lib/ephy-string.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'lib/ephy-string.c') diff --git a/lib/ephy-string.c b/lib/ephy-string.c index f16571cd1..3eb991573 100644 --- a/lib/ephy-string.c +++ b/lib/ephy-string.c @@ -134,3 +134,51 @@ ephy_string_shorten (char *str, return new_str; } + +/* This is a collation key that is very very likely to sort before any + collation key that libc strxfrm generates. We use this before any + special case (dot or number) to make sure that its sorted before + anything else. + */ +#define COLLATION_SENTINEL "\1\1\1" + +/** + * ephy_string_collate_key_for_domain: + * @host: + * @len: the length of @host, or -1 to use the entire null-terminated @host string + * + * Return value: a collation key for @host. + */ +char* +ephy_string_collate_key_for_domain (const char *str, + gssize len) +{ + GString *result; + const char *dot; + gssize newlen; + + if (len < 0) len = strlen (str); + + result = g_string_sized_new (len + 6 * strlen (COLLATION_SENTINEL)); + + /* Note that we could do even better by using + * g_utf8_collate_key_for_filename on the dot-separated + * components, but this seems good enough for now. + */ + while ((dot = g_strrstr_len (str, len, ".")) != NULL) + { + newlen = dot - str; + + g_string_append_len (result, dot + 1, len - newlen - 1); + g_string_append (result, COLLATION_SENTINEL); + + len = newlen; + } + + if (len > 0) + { + g_string_append_len (result, str, len); + } + + return g_string_free (result, FALSE); +} -- cgit v1.2.3