diff options
| author | Stefan Monnier | 2010-09-30 01:28:20 +0200 |
|---|---|---|
| committer | Stefan Monnier | 2010-09-30 01:28:20 +0200 |
| commit | a01a7932080e8a6e7bc8472c58cefabcc2c37df3 (patch) | |
| tree | 94b28b19c8f1536e76ffe7d5826811b74a79e3a5 /src/character.c | |
| parent | cc390e46c7ba95b76ea133d98fd386214cd01709 (diff) | |
| parent | 6b0f7311f16646e0de2045b2410e20921901c616 (diff) | |
| download | emacs-a01a7932080e8a6e7bc8472c58cefabcc2c37df3.tar.gz emacs-a01a7932080e8a6e7bc8472c58cefabcc2c37df3.zip | |
Merge from trunk
Diffstat (limited to 'src/character.c')
| -rw-r--r-- | src/character.c | 86 |
1 files changed, 50 insertions, 36 deletions
diff --git a/src/character.c b/src/character.c index c4a3a008bcd..d80f8139486 100644 --- a/src/character.c +++ b/src/character.c | |||
| @@ -378,11 +378,12 @@ usage: (char-width CHAR) */) | |||
| 378 | characters and bytes of the substring in *NCHARS and *NBYTES | 378 | characters and bytes of the substring in *NCHARS and *NBYTES |
| 379 | respectively. */ | 379 | respectively. */ |
| 380 | 380 | ||
| 381 | int | 381 | EMACS_INT |
| 382 | c_string_width (const unsigned char *str, int len, int precision, int *nchars, int *nbytes) | 382 | c_string_width (const unsigned char *str, EMACS_INT len, int precision, |
| 383 | EMACS_INT *nchars, EMACS_INT *nbytes) | ||
| 383 | { | 384 | { |
| 384 | int i = 0, i_byte = 0; | 385 | EMACS_INT i = 0, i_byte = 0; |
| 385 | int width = 0; | 386 | EMACS_INT width = 0; |
| 386 | struct Lisp_Char_Table *dp = buffer_display_table (); | 387 | struct Lisp_Char_Table *dp = buffer_display_table (); |
| 387 | 388 | ||
| 388 | while (i_byte < len) | 389 | while (i_byte < len) |
| @@ -429,8 +430,8 @@ c_string_width (const unsigned char *str, int len, int precision, int *nchars, i | |||
| 429 | current buffer. The width is measured by how many columns it | 430 | current buffer. The width is measured by how many columns it |
| 430 | occupies on the screen. */ | 431 | occupies on the screen. */ |
| 431 | 432 | ||
| 432 | int | 433 | EMACS_INT |
| 433 | strwidth (const unsigned char *str, int len) | 434 | strwidth (const unsigned char *str, EMACS_INT len) |
| 434 | { | 435 | { |
| 435 | return c_string_width (str, len, -1, NULL, NULL); | 436 | return c_string_width (str, len, -1, NULL, NULL); |
| 436 | } | 437 | } |
| @@ -442,17 +443,18 @@ strwidth (const unsigned char *str, int len) | |||
| 442 | PRECISION, and set number of characters and bytes of the substring | 443 | PRECISION, and set number of characters and bytes of the substring |
| 443 | in *NCHARS and *NBYTES respectively. */ | 444 | in *NCHARS and *NBYTES respectively. */ |
| 444 | 445 | ||
| 445 | int | 446 | EMACS_INT |
| 446 | lisp_string_width (Lisp_Object string, int precision, int *nchars, int *nbytes) | 447 | lisp_string_width (Lisp_Object string, int precision, |
| 448 | EMACS_INT *nchars, EMACS_INT *nbytes) | ||
| 447 | { | 449 | { |
| 448 | int len = SCHARS (string); | 450 | EMACS_INT len = SCHARS (string); |
| 449 | /* This set multibyte to 0 even if STRING is multibyte when it | 451 | /* This set multibyte to 0 even if STRING is multibyte when it |
| 450 | contains only ascii and eight-bit-graphic, but that's | 452 | contains only ascii and eight-bit-graphic, but that's |
| 451 | intentional. */ | 453 | intentional. */ |
| 452 | int multibyte = len < SBYTES (string); | 454 | int multibyte = len < SBYTES (string); |
| 453 | unsigned char *str = SDATA (string); | 455 | unsigned char *str = SDATA (string); |
| 454 | int i = 0, i_byte = 0; | 456 | EMACS_INT i = 0, i_byte = 0; |
| 455 | int width = 0; | 457 | EMACS_INT width = 0; |
| 456 | struct Lisp_Char_Table *dp = buffer_display_table (); | 458 | struct Lisp_Char_Table *dp = buffer_display_table (); |
| 457 | 459 | ||
| 458 | while (i < len) | 460 | while (i < len) |
| @@ -570,11 +572,11 @@ EMACS_INT | |||
| 570 | multibyte_chars_in_text (const unsigned char *ptr, EMACS_INT nbytes) | 572 | multibyte_chars_in_text (const unsigned char *ptr, EMACS_INT nbytes) |
| 571 | { | 573 | { |
| 572 | const unsigned char *endp = ptr + nbytes; | 574 | const unsigned char *endp = ptr + nbytes; |
| 573 | int chars = 0; | 575 | EMACS_INT chars = 0; |
| 574 | 576 | ||
| 575 | while (ptr < endp) | 577 | while (ptr < endp) |
| 576 | { | 578 | { |
| 577 | int len = MULTIBYTE_LENGTH (ptr, endp); | 579 | EMACS_INT len = MULTIBYTE_LENGTH (ptr, endp); |
| 578 | 580 | ||
| 579 | if (len == 0) | 581 | if (len == 0) |
| 580 | abort (); | 582 | abort (); |
| @@ -592,10 +594,11 @@ multibyte_chars_in_text (const unsigned char *ptr, EMACS_INT nbytes) | |||
| 592 | represented by 2-byte in a multibyte text. */ | 594 | represented by 2-byte in a multibyte text. */ |
| 593 | 595 | ||
| 594 | void | 596 | void |
| 595 | parse_str_as_multibyte (const unsigned char *str, int len, int *nchars, int *nbytes) | 597 | parse_str_as_multibyte (const unsigned char *str, EMACS_INT len, |
| 598 | EMACS_INT *nchars, EMACS_INT *nbytes) | ||
| 596 | { | 599 | { |
| 597 | const unsigned char *endp = str + len; | 600 | const unsigned char *endp = str + len; |
| 598 | int n, chars = 0, bytes = 0; | 601 | EMACS_INT n, chars = 0, bytes = 0; |
| 599 | 602 | ||
| 600 | if (len >= MAX_MULTIBYTE_LENGTH) | 603 | if (len >= MAX_MULTIBYTE_LENGTH) |
| 601 | { | 604 | { |
| @@ -633,12 +636,13 @@ parse_str_as_multibyte (const unsigned char *str, int len, int *nchars, int *nby | |||
| 633 | area and that is enough. Return the number of bytes of the | 636 | area and that is enough. Return the number of bytes of the |
| 634 | resulting text. */ | 637 | resulting text. */ |
| 635 | 638 | ||
| 636 | int | 639 | EMACS_INT |
| 637 | str_as_multibyte (unsigned char *str, int len, int nbytes, int *nchars) | 640 | str_as_multibyte (unsigned char *str, EMACS_INT len, EMACS_INT nbytes, |
| 641 | EMACS_INT *nchars) | ||
| 638 | { | 642 | { |
| 639 | unsigned char *p = str, *endp = str + nbytes; | 643 | unsigned char *p = str, *endp = str + nbytes; |
| 640 | unsigned char *to; | 644 | unsigned char *to; |
| 641 | int chars = 0; | 645 | EMACS_INT chars = 0; |
| 642 | int n; | 646 | int n; |
| 643 | 647 | ||
| 644 | if (nbytes >= MAX_MULTIBYTE_LENGTH) | 648 | if (nbytes >= MAX_MULTIBYTE_LENGTH) |
| @@ -709,11 +713,11 @@ str_as_multibyte (unsigned char *str, int len, int nbytes, int *nchars) | |||
| 709 | bytes it may ocupy when converted to multibyte string by | 713 | bytes it may ocupy when converted to multibyte string by |
| 710 | `str_to_multibyte'. */ | 714 | `str_to_multibyte'. */ |
| 711 | 715 | ||
| 712 | int | 716 | EMACS_INT |
| 713 | parse_str_to_multibyte (const unsigned char *str, int len) | 717 | parse_str_to_multibyte (const unsigned char *str, EMACS_INT len) |
| 714 | { | 718 | { |
| 715 | const unsigned char *endp = str + len; | 719 | const unsigned char *endp = str + len; |
| 716 | int bytes; | 720 | EMACS_INT bytes; |
| 717 | 721 | ||
| 718 | for (bytes = 0; str < endp; str++) | 722 | for (bytes = 0; str < endp; str++) |
| 719 | bytes += (*str < 0x80) ? 1 : 2; | 723 | bytes += (*str < 0x80) ? 1 : 2; |
| @@ -727,8 +731,8 @@ parse_str_to_multibyte (const unsigned char *str, int len) | |||
| 727 | that we can use LEN bytes at STR as a work area and that is | 731 | that we can use LEN bytes at STR as a work area and that is |
| 728 | enough. */ | 732 | enough. */ |
| 729 | 733 | ||
| 730 | int | 734 | EMACS_INT |
| 731 | str_to_multibyte (unsigned char *str, int len, int bytes) | 735 | str_to_multibyte (unsigned char *str, EMACS_INT len, EMACS_INT bytes) |
| 732 | { | 736 | { |
| 733 | unsigned char *p = str, *endp = str + bytes; | 737 | unsigned char *p = str, *endp = str + bytes; |
| 734 | unsigned char *to; | 738 | unsigned char *to; |
| @@ -756,8 +760,8 @@ str_to_multibyte (unsigned char *str, int len, int bytes) | |||
| 756 | actually converts characters in the range 0x80..0xFF to | 760 | actually converts characters in the range 0x80..0xFF to |
| 757 | unibyte. */ | 761 | unibyte. */ |
| 758 | 762 | ||
| 759 | int | 763 | EMACS_INT |
| 760 | str_as_unibyte (unsigned char *str, int bytes) | 764 | str_as_unibyte (unsigned char *str, EMACS_INT bytes) |
| 761 | { | 765 | { |
| 762 | const unsigned char *p = str, *endp = str + bytes; | 766 | const unsigned char *p = str, *endp = str + bytes; |
| 763 | unsigned char *to; | 767 | unsigned char *to; |
| @@ -818,14 +822,14 @@ str_to_unibyte (const unsigned char *src, unsigned char *dst, EMACS_INT chars, i | |||
| 818 | } | 822 | } |
| 819 | 823 | ||
| 820 | 824 | ||
| 821 | int | 825 | EMACS_INT |
| 822 | string_count_byte8 (Lisp_Object string) | 826 | string_count_byte8 (Lisp_Object string) |
| 823 | { | 827 | { |
| 824 | int multibyte = STRING_MULTIBYTE (string); | 828 | int multibyte = STRING_MULTIBYTE (string); |
| 825 | int nbytes = SBYTES (string); | 829 | EMACS_INT nbytes = SBYTES (string); |
| 826 | unsigned char *p = SDATA (string); | 830 | unsigned char *p = SDATA (string); |
| 827 | unsigned char *pend = p + nbytes; | 831 | unsigned char *pend = p + nbytes; |
| 828 | int count = 0; | 832 | EMACS_INT count = 0; |
| 829 | int c, len; | 833 | int c, len; |
| 830 | 834 | ||
| 831 | if (multibyte) | 835 | if (multibyte) |
| @@ -851,10 +855,10 @@ string_count_byte8 (Lisp_Object string) | |||
| 851 | Lisp_Object | 855 | Lisp_Object |
| 852 | string_escape_byte8 (Lisp_Object string) | 856 | string_escape_byte8 (Lisp_Object string) |
| 853 | { | 857 | { |
| 854 | int nchars = SCHARS (string); | 858 | EMACS_INT nchars = SCHARS (string); |
| 855 | int nbytes = SBYTES (string); | 859 | EMACS_INT nbytes = SBYTES (string); |
| 856 | int multibyte = STRING_MULTIBYTE (string); | 860 | int multibyte = STRING_MULTIBYTE (string); |
| 857 | int byte8_count; | 861 | EMACS_INT byte8_count; |
| 858 | const unsigned char *src, *src_end; | 862 | const unsigned char *src, *src_end; |
| 859 | unsigned char *dst; | 863 | unsigned char *dst; |
| 860 | Lisp_Object val; | 864 | Lisp_Object val; |
| @@ -869,12 +873,22 @@ string_escape_byte8 (Lisp_Object string) | |||
| 869 | return string; | 873 | return string; |
| 870 | 874 | ||
| 871 | if (multibyte) | 875 | if (multibyte) |
| 872 | /* Convert 2-byte sequence of byte8 chars to 4-byte octal. */ | 876 | { |
| 873 | val = make_uninit_multibyte_string (nchars + byte8_count * 3, | 877 | if ((MOST_POSITIVE_FIXNUM - nchars) / 3 < byte8_count |
| 874 | nbytes + byte8_count * 2); | 878 | || (MOST_POSITIVE_FIXNUM - nbytes) / 2 < byte8_count) |
| 879 | error ("Maximum string size exceeded"); | ||
| 880 | |||
| 881 | /* Convert 2-byte sequence of byte8 chars to 4-byte octal. */ | ||
| 882 | val = make_uninit_multibyte_string (nchars + byte8_count * 3, | ||
| 883 | nbytes + byte8_count * 2); | ||
| 884 | } | ||
| 875 | else | 885 | else |
| 876 | /* Convert 1-byte sequence of byte8 chars to 4-byte octal. */ | 886 | { |
| 877 | val = make_uninit_string (nbytes + byte8_count * 3); | 887 | if ((MOST_POSITIVE_FIXNUM - nchars) / 3 < byte8_count) |
| 888 | error ("Maximum string size exceeded"); | ||
| 889 | /* Convert 1-byte sequence of byte8 chars to 4-byte octal. */ | ||
| 890 | val = make_uninit_string (nbytes + byte8_count * 3); | ||
| 891 | } | ||
| 878 | 892 | ||
| 879 | src = SDATA (string); | 893 | src = SDATA (string); |
| 880 | src_end = src + nbytes; | 894 | src_end = src + nbytes; |