1 --- eel-2.10.1/eel/eel-string.c 2002-03-19 03:05:08.000000000 +0530 2 +++ eel-2.10.1-new/eel/eel-string.c 2005-05-13 15:09:48.219632000 +0530 3 @@ -29,6 +29,8 @@ 4 #include <locale.h> 5 #include <stdlib.h> 6 #include <string.h> 7 +#include <ctype.h> 8 +#include <glib.h> 9 10 #if !defined (EEL_OMIT_SELF_CHECK) 11 #include "eel-lib-self-check-functions.h" 12 @@ -326,9 +326,10 @@ 13 guint truncate_length) 14 { 15 char *truncated; 16 - guint length; 17 + guint length, i; 18 guint num_left_chars; 19 guint num_right_chars; 20 + gboolean is_ascii = TRUE, valid_utf8 = TRUE; 21 22 const char delimter[] = "..."; 23 const guint delimter_length = strlen (delimter); 24 @@ -353,10 +354,41 @@ 25 return g_strdup (string); 26 } 27 28 + for (i=0; i<length; i++) { 29 + if (!isascii (string[i])) { 30 + is_ascii = FALSE; 31 + break; 32 + } 33 + } 34 + 35 + if (!is_ascii && g_utf8_validate (string, -1, NULL)) { 36 + valid_utf8 = TRUE; 37 + } 38 + 39 /* Find the 'middle' where the truncation will occur. */ 40 num_left_chars = (truncate_length - delimter_length) / 2; 41 + 42 + if (valid_utf8 && !g_utf8_validate (string + num_left_chars, -1, NULL)) { 43 + gchar *tc; 44 + tc = g_utf8_find_next_char (string + num_left_chars, NULL); 45 + if (tc) { 46 + num_left_chars = (gint) (tc - string); 47 + } 48 + } 49 + 50 num_right_chars = truncate_length - num_left_chars - delimter_length; 51 52 + if (valid_utf8 && !g_utf8_validate (string + length - num_right_chars +1, -1, NULL)) { 53 + gchar *tc; 54 + tc = g_utf8_find_prev_char (string, string + length - num_right_chars + 1); 55 + if (tc) { 56 + num_right_chars = strlen (tc) + 1; 57 + } 58 + } 59 + 60 + if (valid_utf8) 61 + truncate_length = num_left_chars + num_right_chars + delimter_length; 62 + 63 truncated = g_new (char, strlen (string) + 1); 64 65 g_utf8_strncpy (truncated, string, num_left_chars); 66