aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1997-12-31 22:18:06 +0000
committerRichard M. Stallman1997-12-31 22:18:06 +0000
commit6ae1f27ebf96696996056691839da02e70ab8ed9 (patch)
tree2200b9aa77459e40f2a3dc76ffc789db2ebbfae7 /src
parentec7adf2664746ff3bb20c012f685451b9607ef42 (diff)
downloademacs-6ae1f27ebf96696996056691839da02e70ab8ed9.tar.gz
emacs-6ae1f27ebf96696996056691839da02e70ab8ed9.zip
(Fchars_in_string): Update call to CHAR_HEAD_P.
(chars_in_text, str_cmpchar_id, Fcompose_string): Likewise. (Fchar_boundary_p): Always return 0. (Fchars_in_region): Just subtract the arguments. (chars_in_text): New function. (Ffind_charset_region): Scan in bytepos as well as charpos.
Diffstat (limited to 'src')
-rw-r--r--src/charset.c115
1 files changed, 44 insertions, 71 deletions
diff --git a/src/charset.c b/src/charset.c
index 50031b70601..247dd9de3a9 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -651,23 +651,37 @@ Optional arg TABLE if non-nil is a unification table to look up.")
651 Lisp_Object beg, end, table; 651 Lisp_Object beg, end, table;
652{ 652{
653 int charsets[MAX_CHARSET + 1]; 653 int charsets[MAX_CHARSET + 1];
654 int from, to, stop, i; 654 int from, from_byte, to, stop, stop_byte, i;
655 Lisp_Object val; 655 Lisp_Object val;
656 656
657 validate_region (&beg, &end); 657 validate_region (&beg, &end);
658 from = XFASTINT (beg); 658 from = XFASTINT (beg);
659 stop = to = XFASTINT (end); 659 stop = to = XFASTINT (end);
660
660 if (from < GPT && GPT < to) 661 if (from < GPT && GPT < to)
661 stop = GPT; 662 {
663 stop = GPT;
664 stop_byte = GPT_BYTE;
665 }
666 else
667 stop_byte = CHAR_TO_BYTE (stop);
668
669 from_byte = CHAR_TO_BYTE (from);
670
662 bzero (charsets, (MAX_CHARSET + 1) * sizeof (int)); 671 bzero (charsets, (MAX_CHARSET + 1) * sizeof (int));
663 while (1) 672 while (1)
664 { 673 {
665 find_charset_in_str (POS_ADDR (from), stop - from, charsets, table); 674 find_charset_in_str (BYTE_POS_ADDR (from_byte), stop_byte - from_byte,
675 charsets, table);
666 if (stop < to) 676 if (stop < to)
667 from = stop, stop = to; 677 {
678 from = stop, from_byte = stop_byte;
679 stop = to, stop_byte = CHAR_TO_BYTE (stop);
680 }
668 else 681 else
669 break; 682 break;
670 } 683 }
684
671 val = Qnil; 685 val = Qnil;
672 for (i = MAX_CHARSET; i >= 0; i--) 686 for (i = MAX_CHARSET; i >= 0; i--)
673 if (charsets[i]) 687 if (charsets[i])
@@ -989,7 +1003,7 @@ character.")
989 if (*p == LEADING_CODE_COMPOSITION) 1003 if (*p == LEADING_CODE_COMPOSITION)
990 { 1004 {
991 p++; 1005 p++;
992 while (p < endp && ! CHAR_HEAD_P (p)) p++; 1006 while (p < endp && ! CHAR_HEAD_P (*p)) p++;
993 } 1007 }
994 else 1008 else
995 p += BYTES_BY_CHAR_HEAD (*p); 1009 p += BYTES_BY_CHAR_HEAD (*p);
@@ -1001,62 +1015,45 @@ character.")
1001} 1015}
1002 1016
1003DEFUN ("chars-in-region", Fchars_in_region, Schars_in_region, 2, 2, 0, 1017DEFUN ("chars-in-region", Fchars_in_region, Schars_in_region, 2, 2, 0,
1004 "Return number of characters between BEG and END.\n\ 1018 "Return number of characters between BEG and END.")
1005When using multibyte characters, this is not the necessarily same\n\
1006as (- END BEG); that subtraction gives you the number of bytes, which\n\
1007may be more than the number of characters.")
1008 (beg, end) 1019 (beg, end)
1009 Lisp_Object beg, end; 1020 Lisp_Object beg, end;
1010{ 1021{
1011 int from, to, stop; 1022 int from, to;
1012 Lisp_Object val;
1013 int chars = 0;
1014 unsigned char *p, *endp;
1015
1016 validate_region (&beg, &end);
1017 1023
1018 from = min (XFASTINT (beg), XFASTINT (end)); 1024 from = min (XFASTINT (beg), XFASTINT (end));
1019 to = max (XFASTINT (beg), XFASTINT (end)); 1025 to = max (XFASTINT (beg), XFASTINT (end));
1020 p = POS_ADDR (from);
1021 1026
1022 if (NILP (current_buffer->enable_multibyte_characters)) 1027 return to - from;
1023 return make_number (to - from); 1028}
1024 1029
1025 if (from < GPT && GPT <= to) 1030int
1026 { 1031chars_in_text (ptr, nbytes)
1027 stop = GPT; 1032 unsigned char *ptr;
1028 endp = GPT_ADDR; 1033 int nbytes;
1029 } 1034{
1030 else 1035 unsigned char *endp;
1031 { 1036 int chars;
1032 stop = to;
1033 endp = POS_ADDR (stop);
1034 }
1035 1037
1036 while (1) 1038 if (NILP (current_buffer->enable_multibyte_characters))
1037 { 1039 return nbytes;
1038 if (p >= endp)
1039 {
1040 if (stop >= to)
1041 break;
1042 1040
1043 p = POS_ADDR (stop); 1041 endp = ptr + nbytes;
1044 stop = to; 1042 chars = 0;
1045 endp = POS_ADDR (stop);
1046 }
1047 1043
1048 if (*p == LEADING_CODE_COMPOSITION) 1044 while (ptr < endp)
1045 {
1046 if (*ptr == LEADING_CODE_COMPOSITION)
1049 { 1047 {
1050 p++; 1048 ptr++;
1051 while (p < endp && ! CHAR_HEAD_P (p)) p++; 1049 while (ptr < endp && ! CHAR_HEAD_P (*ptr)) ptr++;
1052 } 1050 }
1053 else 1051 else
1054 p += BYTES_BY_CHAR_HEAD (*p); 1052 ptr += BYTES_BY_CHAR_HEAD (*ptr);
1055
1056 chars++; 1053 chars++;
1057 } 1054 }
1058 1055
1059 return make_number (chars); 1056 return chars;
1060} 1057}
1061 1058
1062DEFUN ("char-boundary-p", Fchar_boundary_p, Schar_boundary_p, 1, 1, 0, 1059DEFUN ("char-boundary-p", Fchar_boundary_p, Schar_boundary_p, 1, 1, 0,
@@ -1071,31 +1068,7 @@ If POS is out of range or not at character boundary, return NIL.")
1071 (pos) 1068 (pos)
1072 Lisp_Object pos; 1069 Lisp_Object pos;
1073{ 1070{
1074 Lisp_Object val; 1071 return make_number (0);
1075 int n;
1076
1077 CHECK_NUMBER_COERCE_MARKER (pos, 0);
1078
1079 n = XINT (pos);
1080 if (n < BEGV || n > ZV)
1081 return Qnil;
1082
1083 if (n == ZV || NILP (current_buffer->enable_multibyte_characters))
1084 XSETFASTINT (val, 0);
1085 else
1086 {
1087 unsigned char *p = POS_ADDR (n);
1088
1089 if (SINGLE_BYTE_CHAR_P (*p))
1090 XSETFASTINT (val, 0);
1091 else if (*p == LEADING_CODE_COMPOSITION)
1092 XSETFASTINT (val, 4);
1093 else if (BYTES_BY_CHAR_HEAD (*p) > 1)
1094 XSETFASTINT (val, BYTES_BY_CHAR_HEAD (*p) - 1);
1095 else
1096 val = Qnil;
1097 }
1098 return val;
1099} 1072}
1100 1073
1101DEFUN ("concat-chars", Fconcat_chars, Sconcat_chars, 1, MANY, 0, 1074DEFUN ("concat-chars", Fconcat_chars, Sconcat_chars, 1, MANY, 0,
@@ -1206,7 +1179,7 @@ str_cmpchar_id (str, len)
1206 unsigned char *p, *endp = str + 1, *lastp = str + len; 1179 unsigned char *p, *endp = str + 1, *lastp = str + len;
1207 int bytes; 1180 int bytes;
1208 1181
1209 while (endp < lastp && ! CHAR_HEAD_P (endp)) endp++; 1182 while (endp < lastp && ! CHAR_HEAD_P (*endp)) endp++;
1210 chars = 0; 1183 chars = 0;
1211 p = str + 1 + embedded_rule; 1184 p = str + 1 + embedded_rule;
1212 while (p < endp) 1185 while (p < endp)
@@ -1523,7 +1496,7 @@ DEFUN ("compose-string", Fcompose_string, Scompose_string,
1523 unchanged. */ 1496 unchanged. */
1524 p++; 1497 p++;
1525 ptemp = p; 1498 ptemp = p;
1526 while (! CHAR_HEAD_P (p)) p++; 1499 while (! CHAR_HEAD_P (*p)) p++;
1527 if (i + (p - ptemp) >= MAX_LENGTH_OF_MULTI_BYTE_FORM) 1500 if (i + (p - ptemp) >= MAX_LENGTH_OF_MULTI_BYTE_FORM)
1528 error ("Too long string to be composed: %s", XSTRING (str)->data); 1501 error ("Too long string to be composed: %s", XSTRING (str)->data);
1529 bcopy (ptemp, buf + i, p - ptemp); 1502 bcopy (ptemp, buf + i, p - ptemp);