changeset 90049:73c7169fe4ff

(casify_region): Handle changes in byte-length using replace_range_2 (sync to HEAD).
author Kenichi Handa <handa@m17n.org>
date Mon, 06 Dec 2004 07:41:56 +0000
parents d42c7860cd33
children 1df66cb75f66
files src/casefiddle.c
diffstat 1 files changed, 18 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/casefiddle.c	Wed Nov 24 00:45:25 2004 +0000
+++ b/src/casefiddle.c	Mon Dec 06 07:41:56 2004 +0000
@@ -236,21 +236,29 @@
 	    }
 	  else if (ASCII_CHAR_P (c2) && ASCII_CHAR_P (c))
 	    FETCH_BYTE (start_byte) = c;
-	  else if (len == CHAR_BYTES (c))
+	  else
 	    {
+	      int tolen = CHAR_BYTES (c);
 	      int j;
 	      unsigned char str[MAX_MULTIBYTE_LENGTH];
 
 	      CHAR_STRING (c, str);
-	      for (j = 0; j < len; ++j)
-		FETCH_BYTE (start_byte + j) = str[j];
-	    }
-	  else
-	    {
-	      TEMP_SET_PT_BOTH (start, start_byte);
-	      del_range_2 (start, start_byte, start + 1, start_byte + len, 0);
-	      insert_char (c);
-	      len = CHAR_BYTES (c);
+	      if (len == tolen)
+		{
+		  /* Length is unchanged.  */
+		  for (j = 0; j < len; ++j)
+		    FETCH_BYTE (start_byte + j) = str[j];
+		}
+	      else
+		{
+		  /* Replace one character with the other,
+		     keeping text properties the same.  */
+		  replace_range_2 (start, start_byte,
+				   start + 1, start_byte + len,
+				   str, 1, tolen,
+				   0);
+		  len = tolen;
+		}
 	    }
 	}
       start++;