[Nautilus-list] eel multibyte bug



The eel list column headers have problems truncating strings in multibyte 
locales. Here is a patch.

/ Alex

Index: eel-list-column-title.c
===================================================================
RCS file: /cvs/gnome/eel/eel/eel-list-column-title.c,v
retrieving revision 1.2
diff -u -p -r1.2 eel-list-column-title.c
--- eel-list-column-title.c	2001/04/09 20:42:27	1.2
+++ eel-list-column-title.c	2001/08/27 19:30:40
@@ -371,6 +371,9 @@ get_sort_indicator (GtkWidget *widget, g
 static char *
 truncate_string (const char *string, GdkFont *font, int width, int *final_width)
 {
+	GdkWChar *wc_string;
+	gchar *mb_string;
+	int wc_len;
 	int current_width;
 	int ellipsis_width;
 	int length;
@@ -398,14 +401,21 @@ truncate_string (const char *string, Gdk
 
 	width -= ellipsis_width;
 
-	for (trimmed_length = length - 1; trimmed_length >= 0; trimmed_length--) {
-		current_width = gdk_text_width (font, string, trimmed_length);
+	wc_string = g_new0 (GdkWChar, length + 1);
+	wc_len = gdk_mbstowcs (wc_string, string, length + 1);
+	
+	for (trimmed_length = wc_len - 1; trimmed_length >= 0; trimmed_length--) {
+		current_width = gdk_text_width_wc (font, wc_string, trimmed_length);
 		if (current_width <= width)
 			break;
 	}
-	result = (char *) g_malloc (trimmed_length + 3 + 1);
-	strncpy (result, string, trimmed_length);
-	strcpy (result + trimmed_length, "...");
+	
+	wc_string [trimmed_length] = L'\0';
+	mb_string = gdk_wcstombs (wc_string);
+	result = g_strconcat (mb_string, "...", NULL);
+	
+	g_free (mb_string);
+	g_free (wc_string);
 
 	if (final_width  != NULL) {
 		*final_width = current_width + ellipsis_width;





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]