diff options
| author | Richard M. Stallman | 1998-02-02 01:03:10 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-02-02 01:03:10 +0000 |
| commit | 6d4752042a7e93529e8d166c146d5ef53e71f2d6 (patch) | |
| tree | e2df4ea77b482df41abd9ca302b188dff4de90a2 /src | |
| parent | 7e97482bb7e1567bba734da8b8aedaa4abe3a816 (diff) | |
| download | emacs-6d4752042a7e93529e8d166c146d5ef53e71f2d6.tar.gz emacs-6d4752042a7e93529e8d166c146d5ef53e71f2d6.zip | |
(concat): If making a string, a nonempty bool-vector is error.
(string_make_multibyte): In all-ASCII case, return orig STRING.
(Fstring_as_unibyte): New function.
(Fstring_as_multibyte): New function.
(syms_of_fns): defsubr them.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fns.c | 74 |
1 files changed, 69 insertions, 5 deletions
| @@ -460,6 +460,8 @@ concat (nargs, args, target_type, last_special) | |||
| 460 | if (this_len_byte > 1) | 460 | if (this_len_byte > 1) |
| 461 | some_multibyte = 1; | 461 | some_multibyte = 1; |
| 462 | } | 462 | } |
| 463 | else if (BOOL_VECTOR_P (this) && XBOOL_VECTOR (this)->size > 0) | ||
| 464 | wrong_type_argument (Qintegerp, Faref (this, make_number (0))); | ||
| 463 | else if (CONSP (this)) | 465 | else if (CONSP (this)) |
| 464 | for (; CONSP (this); this = XCONS (this)->cdr) | 466 | for (; CONSP (this); this = XCONS (this)->cdr) |
| 465 | { | 467 | { |
| @@ -786,6 +788,11 @@ string_make_multibyte (string) | |||
| 786 | 788 | ||
| 787 | nbytes = count_size_as_multibyte (XSTRING (string)->data, | 789 | nbytes = count_size_as_multibyte (XSTRING (string)->data, |
| 788 | XSTRING (string)->size); | 790 | XSTRING (string)->size); |
| 791 | /* If all the chars are ASCII, they won't need any more bytes | ||
| 792 | once converted. In that case, we can return STRING itself. */ | ||
| 793 | if (nbytes == XSTRING (string)->size_byte) | ||
| 794 | return string; | ||
| 795 | |||
| 789 | buf = (unsigned char *) alloca (nbytes); | 796 | buf = (unsigned char *) alloca (nbytes); |
| 790 | copy_text (XSTRING (string)->data, buf, XSTRING (string)->size_byte, | 797 | copy_text (XSTRING (string)->data, buf, XSTRING (string)->size_byte, |
| 791 | 0, 1); | 798 | 0, 1); |
| @@ -829,6 +836,42 @@ DEFUN ("string-make-unibyte", Fstring_make_unibyte, Sstring_make_unibyte, | |||
| 829 | { | 836 | { |
| 830 | return string_make_unibyte (string); | 837 | return string_make_unibyte (string); |
| 831 | } | 838 | } |
| 839 | |||
| 840 | DEFUN ("string-as-unibyte", Fstring_as_unibyte, Sstring_as_unibyte, | ||
| 841 | 1, 1, 0, | ||
| 842 | "Return a unibyte string with the same individual bytes as STRING.\n\ | ||
| 843 | If STRING is unibyte, the result is STRING itself.") | ||
| 844 | (string) | ||
| 845 | Lisp_Object string; | ||
| 846 | { | ||
| 847 | if (STRING_MULTIBYTE (string)) | ||
| 848 | { | ||
| 849 | string = Fcopy_sequence (string); | ||
| 850 | XSTRING (string)->size = XSTRING (string)->size_byte; | ||
| 851 | } | ||
| 852 | return string; | ||
| 853 | } | ||
| 854 | |||
| 855 | DEFUN ("string-as-multibyte", Fstring_as_multibyte, Sstring_as_multibyte, | ||
| 856 | 1, 1, 0, | ||
| 857 | "Return a multibyte string with the same individual bytes as STRING.\n\ | ||
| 858 | If STRING is multibyte, the result is STRING itself.") | ||
| 859 | (string) | ||
| 860 | Lisp_Object string; | ||
| 861 | { | ||
| 862 | if (! STRING_MULTIBYTE (string)) | ||
| 863 | { | ||
| 864 | int newlen = chars_in_text (XSTRING (string)->data, | ||
| 865 | XSTRING (string)->size_byte); | ||
| 866 | /* If all the chars are ASCII, STRING is already suitable. */ | ||
| 867 | if (newlen != XSTRING (string)->size_byte) | ||
| 868 | { | ||
| 869 | string = Fcopy_sequence (string); | ||
| 870 | XSTRING (string)->size = newlen; | ||
| 871 | } | ||
| 872 | } | ||
| 873 | return string; | ||
| 874 | } | ||
| 832 | 875 | ||
| 833 | DEFUN ("copy-alist", Fcopy_alist, Scopy_alist, 1, 1, 0, | 876 | DEFUN ("copy-alist", Fcopy_alist, Scopy_alist, 1, 1, 0, |
| 834 | "Return a copy of ALIST.\n\ | 877 | "Return a copy of ALIST.\n\ |
| @@ -1683,9 +1726,9 @@ DEFUN ("set-char-table-extra-slot", Fset_char_table_extra_slot, | |||
| 1683 | DEFUN ("char-table-range", Fchar_table_range, Schar_table_range, | 1726 | DEFUN ("char-table-range", Fchar_table_range, Schar_table_range, |
| 1684 | 2, 2, 0, | 1727 | 2, 2, 0, |
| 1685 | "Return the value in CHAR-TABLE for a range of characters RANGE.\n\ | 1728 | "Return the value in CHAR-TABLE for a range of characters RANGE.\n\ |
| 1686 | RANGE should be t (for all characters), nil (for the default value)\n\ | 1729 | RANGE should be nil (for the default value)\n\ |
| 1687 | a vector which identifies a character set or a row of a character set,\n\ | 1730 | a vector which identifies a character set or a row of a character set,\n\ |
| 1688 | or a character code.") | 1731 | a character set name, or a character code.") |
| 1689 | (char_table, range) | 1732 | (char_table, range) |
| 1690 | Lisp_Object char_table, range; | 1733 | Lisp_Object char_table, range; |
| 1691 | { | 1734 | { |
| @@ -1697,10 +1740,19 @@ or a character code.") | |||
| 1697 | return XCHAR_TABLE (char_table)->defalt; | 1740 | return XCHAR_TABLE (char_table)->defalt; |
| 1698 | else if (INTEGERP (range)) | 1741 | else if (INTEGERP (range)) |
| 1699 | return Faref (char_table, range); | 1742 | return Faref (char_table, range); |
| 1743 | else if (SYMBOLP (range)) | ||
| 1744 | { | ||
| 1745 | Lisp_Object charset_info; | ||
| 1746 | |||
| 1747 | charset_info = Fget (range, Qcharset); | ||
| 1748 | CHECK_VECTOR (charset_info, 0); | ||
| 1749 | |||
| 1750 | return Faref (char_table, XVECTOR (charset_info)->contents[0] + 128); | ||
| 1751 | } | ||
| 1700 | else if (VECTORP (range)) | 1752 | else if (VECTORP (range)) |
| 1701 | { | 1753 | { |
| 1702 | if (XVECTOR (range)->size == 1) | 1754 | if (XVECTOR (range)->size == 1) |
| 1703 | return Faref (char_table, XVECTOR (range)->contents[0]); | 1755 | return Faref (char_table, XVECTOR (range)->contents[0] + 128); |
| 1704 | else | 1756 | else |
| 1705 | { | 1757 | { |
| 1706 | int size = XVECTOR (range)->size; | 1758 | int size = XVECTOR (range)->size; |
| @@ -1720,7 +1772,7 @@ DEFUN ("set-char-table-range", Fset_char_table_range, Sset_char_table_range, | |||
| 1720 | "Set the value in CHAR-TABLE for a range of characters RANGE to VALUE.\n\ | 1772 | "Set the value in CHAR-TABLE for a range of characters RANGE to VALUE.\n\ |
| 1721 | RANGE should be t (for all characters), nil (for the default value)\n\ | 1773 | RANGE should be t (for all characters), nil (for the default value)\n\ |
| 1722 | a vector which identifies a character set or a row of a character set,\n\ | 1774 | a vector which identifies a character set or a row of a character set,\n\ |
| 1723 | or a character code.") | 1775 | a coding system, or a character code.") |
| 1724 | (char_table, range, value) | 1776 | (char_table, range, value) |
| 1725 | Lisp_Object char_table, range, value; | 1777 | Lisp_Object char_table, range, value; |
| 1726 | { | 1778 | { |
| @@ -1733,12 +1785,22 @@ or a character code.") | |||
| 1733 | XCHAR_TABLE (char_table)->contents[i] = value; | 1785 | XCHAR_TABLE (char_table)->contents[i] = value; |
| 1734 | else if (EQ (range, Qnil)) | 1786 | else if (EQ (range, Qnil)) |
| 1735 | XCHAR_TABLE (char_table)->defalt = value; | 1787 | XCHAR_TABLE (char_table)->defalt = value; |
| 1788 | else if (SYMBOLP (range)) | ||
| 1789 | { | ||
| 1790 | Lisp_Object charset_info; | ||
| 1791 | |||
| 1792 | charset_info = Fget (range, Qcharset); | ||
| 1793 | CHECK_VECTOR (charset_info, 0); | ||
| 1794 | |||
| 1795 | return Faset (char_table, XVECTOR (charset_info)->contents[0] + 128, | ||
| 1796 | value); | ||
| 1797 | } | ||
| 1736 | else if (INTEGERP (range)) | 1798 | else if (INTEGERP (range)) |
| 1737 | Faset (char_table, range, value); | 1799 | Faset (char_table, range, value); |
| 1738 | else if (VECTORP (range)) | 1800 | else if (VECTORP (range)) |
| 1739 | { | 1801 | { |
| 1740 | if (XVECTOR (range)->size == 1) | 1802 | if (XVECTOR (range)->size == 1) |
| 1741 | return Faset (char_table, XVECTOR (range)->contents[0], value); | 1803 | return Faset (char_table, XVECTOR (range)->contents[0] + 128, value); |
| 1742 | else | 1804 | else |
| 1743 | { | 1805 | { |
| 1744 | int size = XVECTOR (range)->size; | 1806 | int size = XVECTOR (range)->size; |
| @@ -2483,6 +2545,8 @@ invoked by mouse clicks and mouse menu items."); | |||
| 2483 | defsubr (&Scopy_sequence); | 2545 | defsubr (&Scopy_sequence); |
| 2484 | defsubr (&Sstring_make_multibyte); | 2546 | defsubr (&Sstring_make_multibyte); |
| 2485 | defsubr (&Sstring_make_unibyte); | 2547 | defsubr (&Sstring_make_unibyte); |
| 2548 | defsubr (&Sstring_as_multibyte); | ||
| 2549 | defsubr (&Sstring_as_unibyte); | ||
| 2486 | defsubr (&Scopy_alist); | 2550 | defsubr (&Scopy_alist); |
| 2487 | defsubr (&Ssubstring); | 2551 | defsubr (&Ssubstring); |
| 2488 | defsubr (&Snthcdr); | 2552 | defsubr (&Snthcdr); |