comparison src/fns.c @ 20813:b040da7cfab8

(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.
author Richard M. Stallman <rms@gnu.org>
date Mon, 02 Feb 1998 01:03:10 +0000
parents 219fdecc30d3
children 8f6d92b4f48a
comparison
equal deleted inserted replaced
20812:d21a1c41800f 20813:b040da7cfab8
458 this_len_byte = XFASTINT (Fchar_bytes (ch)); 458 this_len_byte = XFASTINT (Fchar_bytes (ch));
459 result_len_byte += this_len_byte; 459 result_len_byte += this_len_byte;
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 {
466 ch = XCONS (this)->car; 468 ch = XCONS (this)->car;
467 if (! INTEGERP (ch)) 469 if (! INTEGERP (ch))
784 if (STRING_MULTIBYTE (string)) 786 if (STRING_MULTIBYTE (string))
785 return string; 787 return 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);
792 799
793 return make_multibyte_string (buf, XSTRING (string)->size, nbytes); 800 return make_multibyte_string (buf, XSTRING (string)->size, nbytes);
826 "Return the unibyte equivalent of STRING.") 833 "Return the unibyte equivalent of STRING.")
827 (string) 834 (string)
828 Lisp_Object string; 835 Lisp_Object string;
829 { 836 {
830 return string_make_unibyte (string); 837 return string_make_unibyte (string);
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;
831 } 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\
835 This is an alist which represents the same mapping from objects to objects,\n\ 878 This is an alist which represents the same mapping from objects to objects,\n\
1681 } 1724 }
1682 1725
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 {
1692 int i; 1735 int i;
1693 1736
1695 1738
1696 if (EQ (range, Qnil)) 1739 if (EQ (range, Qnil))
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;
1707 Lisp_Object *val = XVECTOR (range)->contents; 1759 Lisp_Object *val = XVECTOR (range)->contents;
1708 Lisp_Object ch = Fmake_char_internal (size <= 0 ? Qnil : val[0], 1760 Lisp_Object ch = Fmake_char_internal (size <= 0 ? Qnil : val[0],
1718 DEFUN ("set-char-table-range", Fset_char_table_range, Sset_char_table_range, 1770 DEFUN ("set-char-table-range", Fset_char_table_range, Sset_char_table_range,
1719 3, 3, 0, 1771 3, 3, 0,
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 {
1727 int i; 1779 int i;
1728 1780
1731 if (EQ (range, Qt)) 1783 if (EQ (range, Qt))
1732 for (i = 0; i < CHAR_TABLE_ORDINARY_SLOTS; i++) 1784 for (i = 0; i < CHAR_TABLE_ORDINARY_SLOTS; i++)
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;
1745 Lisp_Object *val = XVECTOR (range)->contents; 1807 Lisp_Object *val = XVECTOR (range)->contents;
1746 Lisp_Object ch = Fmake_char_internal (size <= 0 ? Qnil : val[0], 1808 Lisp_Object ch = Fmake_char_internal (size <= 0 ? Qnil : val[0],
2481 defsubr (&Sconcat); 2543 defsubr (&Sconcat);
2482 defsubr (&Svconcat); 2544 defsubr (&Svconcat);
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);
2489 defsubr (&Snth); 2553 defsubr (&Snth);
2490 defsubr (&Selt); 2554 defsubr (&Selt);