changeset 94122:c7f0faccd3c2

(Faset): Allow setting a multibyte character in an ASCII-only unibyte string.
author Kenichi Handa <handa@m17n.org>
date Thu, 17 Apr 2008 01:10:58 +0000
parents 21ceec8c4a93
children 0e98230e4151
files src/data.c
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/data.c	Thu Apr 17 01:09:57 2008 +0000
+++ b/src/data.c	Thu Apr 17 01:10:58 2008 +0000
@@ -2093,7 +2093,17 @@
       CHECK_NUMBER (newelt);
 
       if (XINT (newelt) >= 0 && ! SINGLE_BYTE_CHAR_P (XINT (newelt)))
-	args_out_of_range (array, newelt);
+	{
+	  int i;
+
+	  for (i = SBYTES (array) - 1; i >= 0; i--)
+	    if (SREF (array, i) >= 0x80)
+	      args_out_of_range (array, newelt);
+	  /* ARRAY is an ASCII string.  Convert it to a multibyte
+	     string, and try `aset' again.  */
+	  STRING_SET_MULTIBYTE (array);
+	  return Faset (array, idx, newelt);
+	}
       SSET (array, idxval, XINT (newelt));
     }