(Faset): Allow setting a multibyte character in a
authorKenichi Handa <handa@m17n.org>
Thu, 22 Jan 1998 01:26:45 +0000 (01:26 +0000)
committerKenichi Handa <handa@m17n.org>
Thu, 22 Jan 1998 01:26:45 +0000 (01:26 +0000)
multibyte string as far as it doesn't change the size_byte of the
string.

src/data.c

index aa2cfe0..b9f440c 100644 (file)
@@ -1743,22 +1743,25 @@ IDX starts at 0.")
     }
   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);
+      p = &XSTRING (array)->data[idxval_byte];
 
-      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");
+      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");
 
-      CHECK_NUMBER (newelt, 2);
-      XSTRING (array)->data[idxval_byte] = XINT (newelt);
+      CHAR_STRING (XINT (newelt), p, str);
+      if (p != str)
+       bcopy (str, p, actual_len);
     }
   else
     {