aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2005-11-29 23:09:04 +0800
committerChristian Persch <chpe@src.gnome.org>2005-11-29 23:09:04 +0800
commit3a78991995ffbd980f1520a4c666929a7ed8b19c (patch)
tree4f3e057216e3128d2bc60d179351efdd7a866595 /lib
parentdaa303eedb6e900836a721673dcd2af444748c87 (diff)
downloadgsoc2013-epiphany-3a78991995ffbd980f1520a4c666929a7ed8b19c.tar.gz
gsoc2013-epiphany-3a78991995ffbd980f1520a4c666929a7ed8b19c.tar.zst
gsoc2013-epiphany-3a78991995ffbd980f1520a4c666929a7ed8b19c.zip
Add a method to generate collation keys for domain names.
2005-11-29 Christian Persch <chpe@cvs.gnome.org> * 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.
Diffstat (limited to 'lib')
-rw-r--r--lib/ephy-string.c48
-rw-r--r--lib/ephy-string.h3
2 files changed, 51 insertions, 0 deletions
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);
+}
diff --git a/lib/ephy-string.h b/lib/ephy-string.h
index d5b932ba0..6bb50ff3e 100644
--- a/lib/ephy-string.h
+++ b/lib/ephy-string.h
@@ -33,6 +33,9 @@ char *ephy_string_blank_chr (char *source);
char *ephy_string_shorten (char *str,
gsize target_length);
+char *ephy_string_collate_key_for_domain (const char *host,
+ gssize len);
+
G_END_DECLS
#endif