changeset 20716:e915d0141ec7

(Faset): Allow setting a multibyte character in a multibyte string as far as it doesn't change the size_byte of the string.
author Kenichi Handa <handa@m17n.org>
date Thu, 22 Jan 1998 01:26:45 +0000
parents 5e983ddb85c9
children 19463997fbc6
files src/data.c
diffstat 1 files changed, 13 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/data.c	Thu Jan 22 01:26:45 1998 +0000
+++ b/src/data.c	Thu Jan 22 01:26:45 1998 +0000
@@ -1743,22 +1743,25 @@
     }
   else if (STRING_MULTIBYTE (array))
     {
-      Lisp_Object val;
+      Lisp_Object new_len;
       int c, idxval_byte, actual_len;
+      unsigned char *p, *str;
 
       if (idxval < 0 || idxval >= XSTRING (array)->size)
 	args_out_of_range (array, idx);
 
       idxval_byte = string_char_to_byte (array, idxval);
-
-      c = STRING_CHAR_AND_LENGTH (&XSTRING (array)->data[idxval_byte],
-				  XSTRING (array)->size_byte - idxval_byte,
-				  actual_len);
-      if (actual_len != 1)
-	error ("Attempt to store a multibyte character into a string");
-
-      CHECK_NUMBER (newelt, 2);
-      XSTRING (array)->data[idxval_byte] = XINT (newelt);
+      p = &XSTRING (array)->data[idxval_byte];
+
+      actual_len
+	= MULTIBYTE_FORM_LENGTH (p, XSTRING (array)->size_byte - idxval_byte);
+      new_len = Fchar_bytes (newelt);
+      if (actual_len != XINT (new_len))
+	error ("Attempt to change byte length of a string");
+
+      CHAR_STRING (XINT (newelt), p, str);
+      if (p != str)
+	bcopy (str, p, actual_len);
     }
   else
     {