patches/eel-01-multibyte-bookmark-menu.diff
changeset 4737 f4351b2cd9d7
child 5518 235b0b4aa324
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/eel-01-multibyte-bookmark-menu.diff	Fri Dec 10 23:30:10 2004 +0000
@@ -0,0 +1,81 @@
+diff -ru eel-2.6.1.orig/ChangeLog eel-2.6.1/ChangeLog
+--- eel-2.6.1.orig/ChangeLog	Fri Dec  3 11:46:42 2004
++++ eel-2.6.1/ChangeLog	Fri Dec  3 14:37:47 2004
+@@ -1,3 +1,11 @@
++2004-12-03  Suresh Chandrasekharan <[email protected]>
++	
++	Fix for bugster #6184582 [cinnabar]: nautilus truncates certain 
++	i18nalized bookmark entries
++
++	* eel/eel-string.c (eel_str_middle_truncate): Logic for truncating
++	utf8 strings right.
++	
+ 2004-04-19  Alexander Larsson  <[email protected]>
+ 
+ 	* NEWS:
+diff -ru eel-2.6.1.orig/eel/eel-string.c eel-2.6.1/eel/eel-string.c
+--- eel-2.6.1.orig/eel/eel-string.c	Fri Dec  3 11:46:42 2004
++++ eel-2.6.1/eel/eel-string.c	Fri Dec  3 14:26:12 2004
+@@ -28,6 +28,8 @@
+ #include <errno.h>
+ #include <locale.h>
+ #include <stdlib.h>
++#include <ctype.h>
++#include <glib.h>
+ 
+ #if !defined (EEL_OMIT_SELF_CHECK)
+ #include "eel-lib-self-check-functions.h"
+@@ -531,9 +533,10 @@
+ 			      guint truncate_length)
+ {
+ 	char *truncated;
+-	guint length;
++	guint length, i;
+ 	guint num_left_chars;
+ 	guint num_right_chars;
++	gboolean is_ascii = TRUE, valid_utf8 =  TRUE;
+ 
+ 	const char delimter[] = "...";
+ 	const guint delimter_length = strlen (delimter);
+@@ -557,11 +560,41 @@
+ 	if (length <= truncate_length) {
+ 		return g_strdup (string);
+ 	}
++	
++	for (i=0; i<length; i++) {
++		if (!isascii (string[i])) {
++			is_ascii = FALSE;
++			break;
++		}
++	}
+ 
++	if (!is_ascii && g_utf8_validate (string, -1, NULL)) {
++		valid_utf8 = TRUE;
++	}
++
+ 	/* Find the 'middle' where the truncation will occur. */
+ 	num_left_chars = (truncate_length - delimter_length) / 2;
++
++	if (valid_utf8 && !g_utf8_validate (string + num_left_chars, -1, NULL)) {
++		gchar *tc;
++		tc = g_utf8_find_next_char (string + num_left_chars, NULL);
++		if (tc) {
++			num_left_chars = (gint) (tc - string);
++		}
++	}
+ 	num_right_chars = truncate_length - num_left_chars - delimter_length + 1;
+ 
++	if (valid_utf8 && !g_utf8_validate (string + length - num_right_chars + 1, -1, NULL)) {
++		gchar *tc;
++		tc = g_utf8_find_prev_char (string, string + length - num_right_chars + 1);
++		if (tc) {
++			num_right_chars = strlen (tc) + 1;
++		}
++	}
++
++	if (valid_utf8)
++		truncate_length = num_left_chars + num_right_chars + delimter_length;
++
+ 	truncated = g_new (char, truncate_length + 1);
+ 
+ 	strncpy (truncated, string, num_left_chars);