1 --- eel-2.10.1/ChangeLog 2005-04-11 13:06:51.000000000 +0530 2 +++ eel-2.10.1-new/ChangeLog 2005-05-13 15:10:25.055781000 +0530 3 @@ -0,0 +0,8 @@ 4 +2005-05-13 Suresh Chandrasekharan <suresh.chandrasekharan (a] sun.com> 5 + 6 + Fix for bugster #6184582 [cinnabar]: nautilus truncates certain 7 + i18nalized bookmark entries 8 + 9 + * eel/eel-string.c (eel_str_middle_truncate): Logic for truncating 10 + utf8 strings right. 11 + 12 --- eel-2.10.1/eel/eel-string.c 2002-03-19 03:05:08.000000000 +0530 13 +++ eel-2.10.1-new/eel/eel-string.c 2005-05-13 15:09:48.219632000 +0530 14 @@ -28,6 +28,8 @@ 15 #include <errno.h> 16 #include <locale.h> 17 #include <stdlib.h> 18 +#include <ctype.h> 19 +#include <glib.h> 20 21 #if !defined (EEL_OMIT_SELF_CHECK) 22 #include "eel-lib-self-check-functions.h" 23 @@ -531,9 +533,10 @@ eel_str_middle_truncate (const char *str 24 guint truncate_length) 25 { 26 char *truncated; 27 - guint length; 28 + guint length, i; 29 guint num_left_chars; 30 guint num_right_chars; 31 + gboolean is_ascii = TRUE, valid_utf8 = TRUE; 32 33 const char delimter[] = "..."; 34 const guint delimter_length = strlen (delimter); 35 @@ -557,11 +560,41 @@ eel_str_middle_truncate (const char *str 36 if (length <= truncate_length) { 37 return g_strdup (string); 38 } 39 + 40 + for (i=0; i<length; i++) { 41 + if (!isascii (string[i])) { 42 + is_ascii = FALSE; 43 + break; 44 + } 45 + } 46 + 47 + if (!is_ascii && g_utf8_validate (string, -1, NULL)) { 48 + valid_utf8 = TRUE; 49 + } 50 51 /* Find the 'middle' where the truncation will occur. */ 52 num_left_chars = (truncate_length - delimter_length) / 2; 53 + 54 + if (valid_utf8 && !g_utf8_validate (string + num_left_chars, -1, NULL)) { 55 + gchar *tc; 56 + tc = g_utf8_find_next_char (string + num_left_chars, NULL); 57 + if (tc) { 58 + num_left_chars = (gint) (tc - string); 59 + } 60 + } 61 num_right_chars = truncate_length - num_left_chars - delimter_length + 1; 62 63 + if (valid_utf8 && !g_utf8_validate (string + length - num_right_chars + 1, -1, NULL)) { 64 + gchar *tc; 65 + tc = g_utf8_find_prev_char (string, string + length - num_right_chars + 1); 66 + if (tc) { 67 + num_right_chars = strlen (tc) + 1; 68 + } 69 + } 70 + 71 + if (valid_utf8) 72 + truncate_length = num_left_chars + num_right_chars + delimter_length; 73 + 74 truncated = g_new (char, truncate_length + 1); 75 76 strncpy (truncated, string, num_left_chars); 77