changeset 786:a20ff446347e

Compare paths using utf8_collate_key() since paths are utf8-encoded. It fixes bug 1959854.
author zas_
date Thu, 05 Jun 2008 09:24:42 +0000
parents 548b193c084c
children a2209b1f769d
files src/collect.c src/dupe.c src/main.c src/main.h src/search.c
diffstat 5 files changed, 36 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/collect.c	Thu Jun 05 08:41:02 2008 +0000
+++ b/src/collect.c	Thu Jun 05 09:24:42 2008 +0000
@@ -148,7 +148,7 @@
 			return 0;
 			break;
 		case SORT_PATH:
-			return CASE_SORT(cia->fd->path, cib->fd->path); /* FIXME: utf8_collate */
+			return utf8_compare(cia->fd->path, cib->fd->path, options->file_sort.case_sensitive);
 			break;
 #ifdef HAVE_STRVERSCMP
 		case SORT_NUMBER:
--- a/src/dupe.c	Thu Jun 05 08:41:02 2008 +0000
+++ b/src/dupe.c	Thu Jun 05 09:24:42 2008 +0000
@@ -1128,7 +1128,7 @@
 
 	if (mask & DUPE_MATCH_PATH)
 		{
-		if (strcmp(a->fd->path, b->fd->path) != 0) return FALSE;
+		if (utf8_compare(a->fd->path, b->fd->path, TRUE) != 0) return FALSE;
 		}
 	if (mask & DUPE_MATCH_NAME)
 		{
--- a/src/main.c	Thu Jun 05 08:41:02 2008 +0000
+++ b/src/main.c	Thu Jun 05 09:24:42 2008 +0000
@@ -65,6 +65,38 @@
 	return g_strdup(text);
 }
 
+gint utf8_compare(const gchar *s1, const gchar *s2, gboolean case_sensitive)
+{
+	gchar *s1_key, *s2_key;
+	gchar *s1_t, *s2_t;
+	gint ret;
+
+	g_assert(g_utf8_validate(s1, -1, NULL));
+	g_assert(g_utf8_validate(s2, -1, NULL));
+
+	if (!case_sensitive)
+		{
+		s1_t = g_utf8_casefold(s1, -1); 
+		s2_t = g_utf8_casefold(s2, -1);
+		}
+
+	s1_key = g_utf8_collate_key(s1_t, -1);
+	s2_key = g_utf8_collate_key(s2_t, -1);
+
+	ret = strcmp(s1_key, s2_key);
+
+	g_free(s1_key);
+	g_free(s2_key);
+
+	if (!case_sensitive)
+		{
+		g_free(s1_t);
+		g_free(s2_t);
+		}
+
+	return ret;
+}
+
 /* Borrowed from gtkfilesystemunix.c */
 gchar *expand_tilde(const gchar *filename)
 {
--- a/src/main.h	Thu Jun 05 08:41:02 2008 +0000
+++ b/src/main.h	Thu Jun 05 09:24:42 2008 +0000
@@ -136,6 +136,7 @@
 
 gdouble get_zoom_increment(void);
 gchar *utf8_validate_or_convert(const gchar *text);
+gint utf8_compare(const gchar *s1, const gchar *s2, gboolean case_sensitive);
 gchar *expand_tilde(const gchar *filename);
 
 void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event);
--- a/src/search.c	Thu Jun 05 08:41:02 2008 +0000
+++ b/src/search.c	Thu Jun 05 09:24:42 2008 +0000
@@ -2253,7 +2253,7 @@
 			return sort_matchdata_dimensions(fda, fdb);
 			break;
 		case SEARCH_COLUMN_PATH:
-			return CASE_SORT(fda->fd->path, fdb->fd->path); /* FIXME: utf8_collate */
+			return utf8_compare(fda->fd->path, fdb->fd->path, options->file_sort.case_sensitive);
 			break;
 		default:
 			break;