diff options
| author | Kenichi Handa | 2005-12-28 06:02:18 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2005-12-28 06:02:18 +0000 |
| commit | 0aee65b9c0e18b24275f0534cd5f2e246b4a38a3 (patch) | |
| tree | 65523704f98882009cfc51dced9de8626717ba19 /src | |
| parent | 2dc54538959e4485d9cdeff8737d9d9e2122bbcf (diff) | |
| download | emacs-0aee65b9c0e18b24275f0534cd5f2e246b4a38a3.tar.gz emacs-0aee65b9c0e18b24275f0534cd5f2e246b4a38a3.zip | |
(lisp_string_width): Check multibyteness of STRING.
Diffstat (limited to 'src')
| -rw-r--r-- | src/character.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/src/character.c b/src/character.c index 91b889c3836..8f6eda9c91e 100644 --- a/src/character.c +++ b/src/character.c | |||
| @@ -442,6 +442,10 @@ lisp_string_width (string, precision, nchars, nbytes) | |||
| 442 | int precision, *nchars, *nbytes; | 442 | int precision, *nchars, *nbytes; |
| 443 | { | 443 | { |
| 444 | int len = SCHARS (string); | 444 | int len = SCHARS (string); |
| 445 | /* This set multibyte to 0 even if STRING is multibyte when it | ||
| 446 | contains only ascii and eight-bit-graphic, but that's | ||
| 447 | intentional. */ | ||
| 448 | int multibyte = len < SBYTES (string); | ||
| 445 | unsigned char *str = SDATA (string); | 449 | unsigned char *str = SDATA (string); |
| 446 | int i = 0, i_byte = 0; | 450 | int i = 0, i_byte = 0; |
| 447 | int width = 0; | 451 | int width = 0; |
| @@ -462,23 +466,27 @@ lisp_string_width (string, precision, nchars, nbytes) | |||
| 462 | chars = end - i; | 466 | chars = end - i; |
| 463 | bytes = string_char_to_byte (string, end) - i_byte; | 467 | bytes = string_char_to_byte (string, end) - i_byte; |
| 464 | } | 468 | } |
| 465 | else if (dp) | ||
| 466 | { | ||
| 467 | int c = STRING_CHAR_AND_LENGTH (str + i_byte, len - i_byte, bytes); | ||
| 468 | |||
| 469 | chars = 1; | ||
| 470 | val = DISP_CHAR_VECTOR (dp, c); | ||
| 471 | if (VECTORP (val)) | ||
| 472 | thiswidth = XVECTOR (val)->size; | ||
| 473 | else | ||
| 474 | thiswidth = CHAR_WIDTH (c); | ||
| 475 | } | ||
| 476 | else | 469 | else |
| 477 | { | 470 | { |
| 478 | int c = STRING_CHAR_AND_LENGTH (str + i_byte, len - i_byte, bytes); | 471 | int c; |
| 479 | 472 | ||
| 473 | if (multibyte) | ||
| 474 | c = STRING_CHAR_AND_LENGTH (str + i_byte, len - i_byte, bytes); | ||
| 475 | else | ||
| 476 | c = str[i_byte], bytes = 1; | ||
| 480 | chars = 1; | 477 | chars = 1; |
| 481 | thiswidth = CHAR_WIDTH (c); | 478 | if (dp) |
| 479 | { | ||
| 480 | val = DISP_CHAR_VECTOR (dp, c); | ||
| 481 | if (VECTORP (val)) | ||
| 482 | thiswidth = XVECTOR (val)->size; | ||
| 483 | else | ||
| 484 | thiswidth = CHAR_WIDTH (c); | ||
| 485 | } | ||
| 486 | else | ||
| 487 | { | ||
| 488 | thiswidth = CHAR_WIDTH (c); | ||
| 489 | } | ||
| 482 | } | 490 | } |
| 483 | 491 | ||
| 484 | if (precision > 0 | 492 | if (precision > 0 |