comparison src/minibuf.c @ 21244:50929073a0ba

Use STRING_BYTES and SET_STRING_BYTES.
author Richard M. Stallman <rms@gnu.org>
date Sat, 21 Mar 1998 07:06:14 +0000
parents 0ce30e7ba2b8
children 8c50610fbb99
comparison
equal deleted inserted replaced
21243:e82a4a4fa12a 21244:50929073a0ba
478 if (pos != XSTRING (val)->size) 478 if (pos != XSTRING (val)->size)
479 { 479 {
480 /* Ignore trailing whitespace; any other trailing junk is an error. */ 480 /* Ignore trailing whitespace; any other trailing junk is an error. */
481 int i; 481 int i;
482 pos = string_char_to_byte (val, pos); 482 pos = string_char_to_byte (val, pos);
483 for (i = pos; i < XSTRING (val)->size_byte; i++) 483 for (i = pos; i < STRING_BYTES (XSTRING (val)); i++)
484 { 484 {
485 int c = XSTRING (val)->data[i]; 485 int c = XSTRING (val)->data[i];
486 if (c != ' ' && c != '\t' && c != '\n') 486 if (c != ' ' && c != '\t' && c != '\n')
487 error ("Trailing garbage following expression"); 487 error ("Trailing garbage following expression");
488 } 488 }
952 } 952 }
953 953
954 /* Is this element a possible completion? */ 954 /* Is this element a possible completion? */
955 955
956 if (STRINGP (eltstring) 956 if (STRINGP (eltstring)
957 && XSTRING (string)->size_byte <= XSTRING (eltstring)->size_byte 957 && STRING_BYTES (XSTRING (string)) <= STRING_BYTES (XSTRING (eltstring))
958 && 0 > scmp (XSTRING (eltstring)->data, XSTRING (string)->data, 958 && 0 > scmp (XSTRING (eltstring)->data, XSTRING (string)->data,
959 XSTRING (string)->size_byte)) 959 STRING_BYTES (XSTRING (string))))
960 { 960 {
961 /* Yes. */ 961 /* Yes. */
962 Lisp_Object regexps; 962 Lisp_Object regexps;
963 Lisp_Object zero; 963 Lisp_Object zero;
964 XSETFASTINT (zero, 0); 964 XSETFASTINT (zero, 0);
994 994
995 matchcount++; 995 matchcount++;
996 if (NILP (bestmatch)) 996 if (NILP (bestmatch))
997 { 997 {
998 bestmatch = eltstring; 998 bestmatch = eltstring;
999 bestmatchsize = XSTRING (eltstring)->size_byte; 999 bestmatchsize = STRING_BYTES (XSTRING (eltstring));
1000 } 1000 }
1001 else 1001 else
1002 { 1002 {
1003 compare = min (bestmatchsize, XSTRING (eltstring)->size_byte); 1003 compare = min (bestmatchsize, STRING_BYTES (XSTRING (eltstring)));
1004 matchsize = scmp (XSTRING (bestmatch)->data, 1004 matchsize = scmp (XSTRING (bestmatch)->data,
1005 XSTRING (eltstring)->data, 1005 XSTRING (eltstring)->data,
1006 compare); 1006 compare);
1007 if (matchsize < 0) 1007 if (matchsize < 0)
1008 matchsize = compare; 1008 matchsize = compare;
1010 { 1010 {
1011 /* If this is an exact match except for case, 1011 /* If this is an exact match except for case,
1012 use it as the best match rather than one that is not an 1012 use it as the best match rather than one that is not an
1013 exact match. This way, we get the case pattern 1013 exact match. This way, we get the case pattern
1014 of the actual match. */ 1014 of the actual match. */
1015 if ((matchsize == XSTRING (eltstring)->size_byte 1015 if ((matchsize == STRING_BYTES (XSTRING (eltstring))
1016 && matchsize < XSTRING (bestmatch)->size_byte) 1016 && matchsize < STRING_BYTES (XSTRING (bestmatch)))
1017 || 1017 ||
1018 /* If there is more than one exact match ignoring case, 1018 /* If there is more than one exact match ignoring case,
1019 and one of them is exact including case, 1019 and one of them is exact including case,
1020 prefer that one. */ 1020 prefer that one. */
1021 /* If there is no exact match ignoring case, 1021 /* If there is no exact match ignoring case,
1022 prefer a match that does not change the case 1022 prefer a match that does not change the case
1023 of the input. */ 1023 of the input. */
1024 ((matchsize == XSTRING (eltstring)->size_byte) 1024 ((matchsize == STRING_BYTES (XSTRING (eltstring)))
1025 == 1025 ==
1026 (matchsize == XSTRING (bestmatch)->size_byte) 1026 (matchsize == STRING_BYTES (XSTRING (bestmatch)))
1027 && !bcmp (XSTRING (eltstring)->data, 1027 && !bcmp (XSTRING (eltstring)->data,
1028 XSTRING (string)->data, 1028 XSTRING (string)->data,
1029 XSTRING (string)->size_byte) 1029 STRING_BYTES (XSTRING (string)))
1030 && bcmp (XSTRING (bestmatch)->data, 1030 && bcmp (XSTRING (bestmatch)->data,
1031 XSTRING (string)->data, 1031 XSTRING (string)->data,
1032 XSTRING (string)->size_byte))) 1032 STRING_BYTES (XSTRING (string)))))
1033 bestmatch = eltstring; 1033 bestmatch = eltstring;
1034 } 1034 }
1035 bestmatchsize = matchsize; 1035 bestmatchsize = matchsize;
1036 } 1036 }
1037 } 1037 }
1040 if (NILP (bestmatch)) 1040 if (NILP (bestmatch))
1041 return Qnil; /* No completions found */ 1041 return Qnil; /* No completions found */
1042 /* If we are ignoring case, and there is no exact match, 1042 /* If we are ignoring case, and there is no exact match,
1043 and no additional text was supplied, 1043 and no additional text was supplied,
1044 don't change the case of what the user typed. */ 1044 don't change the case of what the user typed. */
1045 if (completion_ignore_case && bestmatchsize == XSTRING (string)->size_byte 1045 if (completion_ignore_case && bestmatchsize == STRING_BYTES (XSTRING (string))
1046 && XSTRING (bestmatch)->size_byte > bestmatchsize) 1046 && STRING_BYTES (XSTRING (bestmatch)) > bestmatchsize)
1047 return string; 1047 return string;
1048 1048
1049 /* Return t if the supplied string is an exact match (counting case); 1049 /* Return t if the supplied string is an exact match (counting case);
1050 it does not require any change to be made. */ 1050 it does not require any change to be made. */
1051 if (matchcount == 1 && bestmatchsize == XSTRING (string)->size_byte 1051 if (matchcount == 1 && bestmatchsize == STRING_BYTES (XSTRING (string))
1052 && !bcmp (XSTRING (bestmatch)->data, XSTRING (string)->data, 1052 && !bcmp (XSTRING (bestmatch)->data, XSTRING (string)->data,
1053 bestmatchsize)) 1053 bestmatchsize))
1054 return Qt; 1054 return Qt;
1055 1055
1056 bestmatchsize = string_byte_to_char (bestmatch, bestmatchsize); 1056 bestmatchsize = string_byte_to_char (bestmatch, bestmatchsize);
1180 } 1180 }
1181 1181
1182 /* Is this element a possible completion? */ 1182 /* Is this element a possible completion? */
1183 1183
1184 if (STRINGP (eltstring) 1184 if (STRINGP (eltstring)
1185 && XSTRING (string)->size_byte <= XSTRING (eltstring)->size_byte 1185 && STRING_BYTES (XSTRING (string)) <= STRING_BYTES (XSTRING (eltstring))
1186 /* If HIDE_SPACES, reject alternatives that start with space 1186 /* If HIDE_SPACES, reject alternatives that start with space
1187 unless the input starts with space. */ 1187 unless the input starts with space. */
1188 && ((XSTRING (string)->size_byte > 0 1188 && ((STRING_BYTES (XSTRING (string)) > 0
1189 && XSTRING (string)->data[0] == ' ') 1189 && XSTRING (string)->data[0] == ' ')
1190 || XSTRING (eltstring)->data[0] != ' ' 1190 || XSTRING (eltstring)->data[0] != ' '
1191 || NILP (hide_spaces)) 1191 || NILP (hide_spaces))
1192 && 0 > scmp (XSTRING (eltstring)->data, XSTRING (string)->data, 1192 && 0 > scmp (XSTRING (eltstring)->data, XSTRING (string)->data,
1193 XSTRING (string)->size_byte)) 1193 STRING_BYTES (XSTRING (string))))
1194 { 1194 {
1195 /* Yes. */ 1195 /* Yes. */
1196 Lisp_Object regexps; 1196 Lisp_Object regexps;
1197 Lisp_Object zero; 1197 Lisp_Object zero;
1198 XSETFASTINT (zero, 0); 1198 XSETFASTINT (zero, 0);
1354 { 1354 {
1355 /* Bypass intern-soft as that loses for nil */ 1355 /* Bypass intern-soft as that loses for nil */
1356 tem = oblookup (Vminibuffer_completion_table, 1356 tem = oblookup (Vminibuffer_completion_table,
1357 XSTRING (txt)->data, 1357 XSTRING (txt)->data,
1358 XSTRING (txt)->size, 1358 XSTRING (txt)->size,
1359 XSTRING (txt)->size_byte); 1359 STRING_BYTES (XSTRING (txt)));
1360 if (!SYMBOLP (tem)) 1360 if (!SYMBOLP (tem))
1361 return Qnil; 1361 return Qnil;
1362 else if (!NILP (Vminibuffer_completion_predicate)) 1362 else if (!NILP (Vminibuffer_completion_predicate))
1363 return call1 (Vminibuffer_completion_predicate, tem); 1363 return call1 (Vminibuffer_completion_predicate, tem);
1364 else 1364 else
1656 if (! EQ (substituted, tem)) 1656 if (! EQ (substituted, tem))
1657 { 1657 {
1658 tem = substituted; 1658 tem = substituted;
1659 Ferase_buffer (); 1659 Ferase_buffer ();
1660 insert_from_string (tem, 0, 0, XSTRING (tem)->size, 1660 insert_from_string (tem, 0, 0, XSTRING (tem)->size,
1661 XSTRING (tem)->size_byte, 0); 1661 STRING_BYTES (XSTRING (tem)), 0);
1662 } 1662 }
1663 } 1663 }
1664 buffer_string = XSTRING (tem)->data; 1664 buffer_string = XSTRING (tem)->data;
1665 completion_string = XSTRING (completion)->data; 1665 completion_string = XSTRING (completion)->data;
1666 buffer_nbytes = XSTRING (tem)->size_byte; /* ie ZV_BYTE - BEGV_BYTE */ 1666 buffer_nbytes = STRING_BYTES (XSTRING (tem)); /* ie ZV_BYTE - BEGV_BYTE */
1667 completion_nbytes = XSTRING (completion)->size_byte; 1667 completion_nbytes = STRING_BYTES (XSTRING (completion));
1668 i_byte = buffer_nbytes - completion_nbytes; 1668 i_byte = buffer_nbytes - completion_nbytes;
1669 if (i_byte > 0 || 1669 if (i_byte > 0 ||
1670 0 <= scmp (buffer_string, completion_string, buffer_nbytes)) 1670 0 <= scmp (buffer_string, completion_string, buffer_nbytes))
1671 { 1671 {
1672 /* Set buffer to longest match of buffer tail and completion head. */ 1672 /* Set buffer to longest match of buffer tail and completion head. */
1714 i gets index in string of where to stop completing. */ 1714 i gets index in string of where to stop completing. */
1715 { 1715 {
1716 int len, c; 1716 int len, c;
1717 1717
1718 completion_string = XSTRING (completion)->data; 1718 completion_string = XSTRING (completion)->data;
1719 for (; i_byte < XSTRING (completion)->size_byte; i_byte += len, i++) 1719 for (; i_byte < STRING_BYTES (XSTRING (completion)); i_byte += len, i++)
1720 { 1720 {
1721 c = STRING_CHAR_AND_LENGTH (completion_string + i_byte, 1721 c = STRING_CHAR_AND_LENGTH (completion_string + i_byte,
1722 XSTRING (completion)->size - i_byte, 1722 XSTRING (completion)->size - i_byte,
1723 len); 1723 len);
1724 if (SYNTAX (c) != Sword) 1724 if (SYNTAX (c) != Sword)