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