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