aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1998-01-09 23:03:25 +0000
committerRichard M. Stallman1998-01-09 23:03:25 +0000
commit87b089add48c722f825cd4cf1a1b3411647ae47e (patch)
tree98024bea1b63b12d1a84c4780a4ca9e91d7c1ba3 /src
parentbff2601e52145ae404fe521f524ecbc2d74a0d4c (diff)
downloademacs-87b089add48c722f825cd4cf1a1b3411647ae47e.tar.gz
emacs-87b089add48c722f825cd4cf1a1b3411647ae47e.zip
(multibyte_chars_in_text): New function.
(Fstring): Use make_multibyte_string. (Fcompose_string): Likewise. (Ffind_charset_string): Handle bytes vs chars in string. Special case for single-byte strings. (Fchars_in_string): Function deleted. (Fstring): Renamed from Fconcat_chars. Handle bytes vs chars in string. (syms_of_charset): Corresponding changes.
Diffstat (limited to 'src')
-rw-r--r--src/charset.c92
1 files changed, 48 insertions, 44 deletions
diff --git a/src/charset.c b/src/charset.c
index 79ee7cdd2a8..51d1a2bc34e 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -701,8 +701,12 @@ Optional arg TABLE if non-nil is a unification table to look up.")
701 Lisp_Object val; 701 Lisp_Object val;
702 702
703 CHECK_STRING (str, 0); 703 CHECK_STRING (str, 0);
704
705 if (! STRING_MULTIBYTE (str))
706 return Qnil;
707
704 bzero (charsets, (MAX_CHARSET + 1) * sizeof (int)); 708 bzero (charsets, (MAX_CHARSET + 1) * sizeof (int));
705 find_charset_in_str (XSTRING (str)->data, XSTRING (str)->size, 709 find_charset_in_str (XSTRING (str)->data, XSTRING (str)->size_byte,
706 charsets, table); 710 charsets, table);
707 val = Qnil; 711 val = Qnil;
708 for (i = MAX_CHARSET; i >= 0; i--) 712 for (i = MAX_CHARSET; i >= 0; i--)
@@ -978,42 +982,6 @@ The returned value is 0 for left-to-right and 1 for right-to-left.")
978 return CHARSET_TABLE_INFO (charset, CHARSET_DIRECTION_IDX); 982 return CHARSET_TABLE_INFO (charset, CHARSET_DIRECTION_IDX);
979} 983}
980 984
981DEFUN ("chars-in-string", Fchars_in_string, Schars_in_string, 1, 1, 0,
982 "Return number of characters in STRING.\n\
983When using multibyte characters, this is not the necessarily same as\n\
984the length of STRING; the length counts a multibyte characters as\n\
985several bytes, but this function counts a multibyte character as one\n\
986character.")
987 (str)
988 Lisp_Object str;
989{
990 Lisp_Object val;
991 unsigned char *p, *endp;
992 int chars;
993
994 CHECK_STRING (str, 0);
995
996 if (NILP (current_buffer->enable_multibyte_characters))
997 return make_number (XSTRING (str)->size);
998
999 p = XSTRING (str)->data; endp = p + XSTRING (str)->size;
1000 chars = 0;
1001 while (p < endp)
1002 {
1003 if (*p == LEADING_CODE_COMPOSITION)
1004 {
1005 p++;
1006 while (p < endp && ! CHAR_HEAD_P (*p)) p++;
1007 }
1008 else
1009 p += BYTES_BY_CHAR_HEAD (*p);
1010 chars++;
1011 }
1012
1013 XSETFASTINT (val, chars);
1014 return val;
1015}
1016
1017DEFUN ("chars-in-region", Fchars_in_region, Schars_in_region, 2, 2, 0, 985DEFUN ("chars-in-region", Fchars_in_region, Schars_in_region, 2, 2, 0,
1018 "Return number of characters between BEG and END.") 986 "Return number of characters between BEG and END.")
1019 (beg, end) 987 (beg, end)
@@ -1027,6 +995,11 @@ DEFUN ("chars-in-region", Fchars_in_region, Schars_in_region, 2, 2, 0,
1027 return to - from; 995 return to - from;
1028} 996}
1029 997
998/* Return the number of characters in the NBYTES bytes at PTR.
999 This works by looking at the contents and checking for multibyte sequences.
1000 However, if the current buffer has enable-multibyte-characters = nil,
1001 we treat each byte as a character. */
1002
1030int 1003int
1031chars_in_text (ptr, nbytes) 1004chars_in_text (ptr, nbytes)
1032 unsigned char *ptr; 1005 unsigned char *ptr;
@@ -1035,7 +1008,9 @@ chars_in_text (ptr, nbytes)
1035 unsigned char *endp; 1008 unsigned char *endp;
1036 int chars; 1009 int chars;
1037 1010
1038 if (NILP (current_buffer->enable_multibyte_characters)) 1011 /* current_buffer is null at early stages of Emacs initialization. */
1012 if (current_buffer == 0
1013 || NILP (current_buffer->enable_multibyte_characters))
1039 return nbytes; 1014 return nbytes;
1040 1015
1041 endp = ptr + nbytes; 1016 endp = ptr + nbytes;
@@ -1056,7 +1031,37 @@ chars_in_text (ptr, nbytes)
1056 return chars; 1031 return chars;
1057} 1032}
1058 1033
1059DEFUN ("concat-chars", Fconcat_chars, Sconcat_chars, 1, MANY, 0, 1034/* Return the number of characters in the NBYTES bytes at PTR.
1035 This works by looking at the contents and checking for multibyte sequences.
1036 It ignores enable-multibyte-characters. */
1037
1038int
1039multibyte_chars_in_text (ptr, nbytes)
1040 unsigned char *ptr;
1041 int nbytes;
1042{
1043 unsigned char *endp;
1044 int chars;
1045
1046 endp = ptr + nbytes;
1047 chars = 0;
1048
1049 while (ptr < endp)
1050 {
1051 if (*ptr == LEADING_CODE_COMPOSITION)
1052 {
1053 ptr++;
1054 while (ptr < endp && ! CHAR_HEAD_P (*ptr)) ptr++;
1055 }
1056 else
1057 ptr += BYTES_BY_CHAR_HEAD (*ptr);
1058 chars++;
1059 }
1060
1061 return chars;
1062}
1063
1064DEFUN ("string", Fstring, Sstring, 1, MANY, 0,
1060 "Concatenate all the argument characters and make the result a string.") 1065 "Concatenate all the argument characters and make the result a string.")
1061 (n, args) 1066 (n, args)
1062 int n; 1067 int n;
@@ -1086,7 +1091,7 @@ DEFUN ("concat-chars", Fconcat_chars, Sconcat_chars, 1, MANY, 0,
1086 p += len; 1091 p += len;
1087 } 1092 }
1088 1093
1089 val = make_string (buf, p - buf); 1094 val = make_multibyte_string (buf, n, p - buf);
1090 return val; 1095 return val;
1091} 1096}
1092 1097
@@ -1459,7 +1464,7 @@ DEFUN ("compose-string", Fcompose_string, Scompose_string,
1459 1464
1460 buf[0] = LEADING_CODE_COMPOSITION; 1465 buf[0] = LEADING_CODE_COMPOSITION;
1461 p = XSTRING (str)->data; 1466 p = XSTRING (str)->data;
1462 pend = p + XSTRING (str)->size; 1467 pend = p + XSTRING (str)->size_byte;
1463 i = 1; 1468 i = 1;
1464 while (p < pend) 1469 while (p < pend)
1465 { 1470 {
@@ -1504,7 +1509,7 @@ DEFUN ("compose-string", Fcompose_string, Scompose_string,
1504 /* STR contains only one character, which can't be composed. */ 1509 /* STR contains only one character, which can't be composed. */
1505 error ("Too short string to be composed: %s", XSTRING (str)->data); 1510 error ("Too short string to be composed: %s", XSTRING (str)->data);
1506 1511
1507 return make_string (buf, i); 1512 return make_multibyte_string (buf, 1, i);
1508} 1513}
1509 1514
1510 1515
@@ -1626,9 +1631,8 @@ syms_of_charset ()
1626 defsubr (&Schar_width); 1631 defsubr (&Schar_width);
1627 defsubr (&Sstring_width); 1632 defsubr (&Sstring_width);
1628 defsubr (&Schar_direction); 1633 defsubr (&Schar_direction);
1629 defsubr (&Schars_in_string);
1630 defsubr (&Schars_in_region); 1634 defsubr (&Schars_in_region);
1631 defsubr (&Sconcat_chars); 1635 defsubr (&Sstring);
1632 defsubr (&Scmpcharp); 1636 defsubr (&Scmpcharp);
1633 defsubr (&Scmpchar_component); 1637 defsubr (&Scmpchar_component);
1634 defsubr (&Scmpchar_cmp_rule); 1638 defsubr (&Scmpchar_cmp_rule);