changeset 90050:1df66cb75f66

(Ftranslate_region_internal): Don't convert unibyte string to multibyte (sync to HEAD).
author Kenichi Handa <handa@m17n.org>
date Mon, 06 Dec 2004 11:34:00 +0000
parents 73c7169fe4ff
children 35aaa83d57ed
files src/editfns.c
diffstat 1 files changed, 41 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/editfns.c	Mon Dec 06 07:41:56 2004 +0000
+++ b/src/editfns.c	Mon Dec 06 11:34:00 2004 +0000
@@ -2884,16 +2884,15 @@
     {
       if (! EQ (XCHAR_TABLE (table)->purpose, Qtranslation_table))
 	error ("Not a translation table");
+      size = MAX_CHAR;
       tt = NULL;
     }
   else
     {
       CHECK_STRING (table);
 
-      if (multibyte != (SCHARS (table) < SBYTES (table)))
-	table = (multibyte
-		 ? string_make_multibyte (table)
-		 : string_make_unibyte (table));
+      if (! multibyte && (SCHARS (table) < SBYTES (table)))
+	table = string_make_unibyte (table);
       string_multibyte = SCHARS (table) < SBYTES (table);
       size = SBYTES (table);
       tt = SDATA (table);
@@ -2914,45 +2913,56 @@
       Lisp_Object val;
 
       if (multibyte)
-	nc = oc = STRING_CHAR_AND_LENGTH (p, 0, len);
+	oc = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, len);
       else
-	nc = oc = *p, len = 1;
-      if (tt)
+	oc = *p, len = 1;
+      if (oc < size)
 	{
-	  if (oc < size)
+	  if (tt)
 	    {
 	      if (string_multibyte)
 		{
 		  str = tt + string_char_to_byte (table, oc);
-		  nc = STRING_CHAR_AND_LENGTH (str, 0, str_len);
+		  nc = STRING_CHAR_AND_LENGTH (str, MAX_MULTIBYTE_LENGTH, 
+					       str_len);
 		}
 	      else
 		{
-		  str = tt + oc;
-		  nc = tt[oc], str_len = 1;
+		  nc = tt[oc];
+		  if (! ASCII_BYTE_P (nc) && multibyte)
+		    {
+		      str_len = BYTE8_STRING (nc, buf);
+		      str = buf;
+		    }
+		  else
+		    {
+		      str_len = 1;
+		      str = tt + oc;
+		    }
 		}
 	    }
-	}
-      else
-	{
-	  val = CHAR_TABLE_REF (table, oc);
-	  if (CHARACTERP (val))
+	  else
 	    {
-	      nc = XFASTINT (val);
-	      str_len = CHAR_STRING (nc, buf);
-	      str = buf;
+	      int c;
+
+	      nc = oc;
+	      val = CHAR_TABLE_REF (table, oc);
+	      if (CHARACTERP (val)
+		  && (c = XINT (val), CHAR_VALID_P (c, 0)))
+		{
+		  nc = c;
+		  str_len = CHAR_STRING (nc, buf);
+		  str = buf;
+		}
+	      else if (VECTORP (val) || (CONSP (val)))
+		{
+		  /* VAL is [TO_CHAR ...] or (([FROM-CHAR ...] .  TO) ...)
+		     where TO is TO-CHAR or [TO-CHAR ...].  */
+		  nc = -1;
+		}
 	    }
-	  else if (VECTORP (val) || (CONSP (val)))
-	    {
-	      /* VAL is [TO_CHAR ...] or (([FROM-CHAR ...] .  TO) ...)
-		 where TO is TO-CHAR or [TO-CHAR ...].  */
-	      nc = -1;
-	    }
-	}
-
-      if (nc != oc)
-	{
-	  if (nc >= 0)
+
+	  if (nc != oc && nc >= 0)
 	    {
 	      /* Simple one char to one char translation.  */
 	      if (len != str_len)
@@ -2975,7 +2985,7 @@
 		}
 	      ++cnt;
 	    }
-	  else
+	  else if (nc < 0)
 	    {
 	      Lisp_Object string;