# HG changeset patch # User Kenichi Handa # Date 1135749738 0 # Node ID d4755c5aa57d271343679aca0191061343fff89e # Parent cd0158e0e9cc6fa5a352bb4cce4e89f6f2354af0 (lisp_string_width): Check multibyteness of STRING. diff -r cd0158e0e9cc -r d4755c5aa57d src/character.c --- 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