changeset 90256:d4755c5aa57d

(lisp_string_width): Check multibyteness of STRING.
author Kenichi Handa <handa@m17n.org>
date Wed, 28 Dec 2005 06:02:18 +0000
parents cd0158e0e9cc
children 5fa2c40cc6a4
files src/character.c
diffstat 1 files changed, 21 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/character.c	Thu Oct 27 06:35:38 2005 +0000
+++ b/src/character.c	Wed Dec 28 06:02:18 2005 +0000
@@ -442,6 +442,10 @@
      int precision, *nchars, *nbytes;
 {
   int len = SCHARS (string);
+  /* This set multibyte to 0 even if STRING is multibyte when it
+     contains only ascii and eight-bit-graphic, but that's
+     intentional.  */
+  int multibyte = len < SBYTES (string);
   unsigned char *str = SDATA (string);
   int i = 0, i_byte = 0;
   int width = 0;
@@ -462,23 +466,27 @@
 	  chars = end - i;
 	  bytes = string_char_to_byte (string, end) - i_byte;
 	}
-      else if (dp)
-	{
-	  int c = STRING_CHAR_AND_LENGTH (str + i_byte, len - i_byte, bytes);
-
-	  chars = 1;
-	  val = DISP_CHAR_VECTOR (dp, c);
-	  if (VECTORP (val))
-	    thiswidth = XVECTOR (val)->size;
-	  else
-	    thiswidth = CHAR_WIDTH (c);
-	}
       else
 	{
-	  int c = STRING_CHAR_AND_LENGTH (str + i_byte, len - i_byte, bytes);
+	  int c;
 
+	  if (multibyte)
+	    c = STRING_CHAR_AND_LENGTH (str + i_byte, len - i_byte, bytes);
+	  else
+	    c = str[i_byte], bytes = 1;
 	  chars = 1;
-	  thiswidth = CHAR_WIDTH (c);
+	  if (dp)
+	    {
+	      val = DISP_CHAR_VECTOR (dp, c);
+	      if (VECTORP (val))
+		thiswidth = XVECTOR (val)->size;
+	      else
+		thiswidth = CHAR_WIDTH (c);
+	    }
+	  else
+	    {
+	      thiswidth = CHAR_WIDTH (c);
+	    }
 	}
 
       if (precision > 0