changeset 25096:1af1088d3812

(string_char_and_length): New. Use it everywhere instead of STRING_CHAR_AND_LENGTH in xdisp.c.
author Gerd Moellmann <gerd@gnu.org>
date Wed, 28 Jul 1999 18:05:44 +0000
parents 514b71b0b8f8
children 65612dade7f5
files src/xdisp.c
diffstat 1 files changed, 38 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/xdisp.c	Wed Jul 28 16:46:30 1999 +0000
+++ b/src/xdisp.c	Wed Jul 28 18:05:44 1999 +0000
@@ -598,6 +598,7 @@
 
 /* Function prototypes.  */
 
+static int string_char_and_length P_ ((unsigned char *, int, int *));
 static struct text_pos display_prop_end P_ ((struct it *, Lisp_Object,
 					     struct text_pos));
 static int compute_window_start_on_continuation_line P_ ((struct window *));
@@ -860,6 +861,31 @@
 			      Utilities
  ***********************************************************************/
 
+/* Return the next character from STR which is MAXLEN bytes long.
+   Return in *LEN the length of the character.  This is like
+   STRING_CHAR_AND_LENGTH but never returns an invalid character.  If
+   we find one, we return a `?', but with the length of the illegal
+   character.  */
+
+static INLINE int
+string_char_and_length (str, max_len, len)
+     unsigned char *str;
+     int max_len, *len;
+{
+  int c;
+
+  c = STRING_CHAR_AND_LENGTH (str, maxlen, *len);
+  if (!CHAR_VALID_P (c, 1))
+    /* We may not change the length here because other places in Emacs
+       don't use this function, i.e. they silently accept illegal
+       characters.  */
+    c = '?';
+
+  return c;
+}
+
+
+
 /* Given a position POS containing a valid character and byte position
    in STRING, return the position NCHARS ahead (NCHARS >= 0).  */
 
@@ -879,7 +905,7 @@
 
       while (nchars--)
 	{
-	  STRING_CHAR_AND_LENGTH (p, rest, len);
+	  string_char_and_length (p, rest, &len);
 	  p += len, rest -= len;
 	  xassert (rest >= 0);
 	  CHARPOS (pos) += 1;
@@ -931,7 +957,7 @@
       SET_TEXT_POS (pos, 0, 0);
       while (charpos--)
 	{
-	  STRING_CHAR_AND_LENGTH (s, rest, len);
+	  string_char_and_length (s, rest, &len);
 	  s += len, rest -= len;
 	  xassert (rest >= 0);
 	  CHARPOS (pos) += 1;
@@ -962,7 +988,7 @@
 
       for (nchars = 0; rest > 0; ++nchars)
 	{
-	  STRING_CHAR_AND_LENGTH (p, rest, len);
+	  string_char_and_length (p, rest, &len);
 	  rest -= len, p += len;
 	}
     }
@@ -1009,7 +1035,7 @@
       int maxlen = ((BYTEPOS (pos) >= GPT_BYTE ? ZV_BYTE : GPT_BYTE)
 		    - BYTEPOS (pos));
       int len;
-      c = STRING_CHAR_AND_LENGTH (p, maxlen, len);
+      c = string_char_and_length (p, maxlen, &len);
     }
   else
     c = *p;
@@ -1955,7 +1981,7 @@
 	  int rest = STRING_BYTES (XSTRING (it->string)) - BYTEPOS (pos);
 	  int c, len, charset;
       
-	  c = STRING_CHAR_AND_LENGTH (p, rest, len);
+	  c = string_char_and_length (p, rest, &len);
 	  charset = CHAR_CHARSET (c);
 	  if (charset != CHARSET_ASCII)
 	    face_id = FACE_FOR_CHARSET (it->f, face_id, charset);
@@ -3599,7 +3625,7 @@
 			   - IT_STRING_BYTEPOS (*it));
 	  unsigned char *s = (XSTRING (it->string)->data
 			      + IT_STRING_BYTEPOS (*it));
-	  it->c = STRING_CHAR_AND_LENGTH (s, remaining, it->len);
+	  it->c = string_char_and_length (s, remaining, &it->len);
 	}
       else
 	{
@@ -3630,7 +3656,7 @@
 			- IT_STRING_BYTEPOS (*it));
 	  unsigned char *s = (XSTRING (it->string)->data
 			      + IT_STRING_BYTEPOS (*it));
-	  it->c = STRING_CHAR_AND_LENGTH (s, maxlen, it->len);
+	  it->c = string_char_and_length (s, maxlen, &it->len);
 	}
       else
 	{
@@ -3688,8 +3714,8 @@
 	 performance problem because there is no noticeable performance
 	 difference between Emacs running in unibyte or multibyte mode.  */
       int maxlen = strlen (it->s) - IT_BYTEPOS (*it);
-      it->c = STRING_CHAR_AND_LENGTH (it->s + IT_BYTEPOS (*it),
-				      maxlen, it->len);
+      it->c = string_char_and_length (it->s + IT_BYTEPOS (*it),
+				      maxlen, &it->len);
     }
   else
     it->c = it->s[IT_BYTEPOS (*it)], it->len = 1;
@@ -3826,7 +3852,7 @@
 	{
 	  int maxlen = ((IT_BYTEPOS (*it) >= GPT_BYTE ? ZV_BYTE : GPT_BYTE)
 			- IT_BYTEPOS (*it));
-	  it->c = STRING_CHAR_AND_LENGTH (p, maxlen, it->len);
+	  it->c = string_char_and_length (p, maxlen, &it->len);
 	}
       else
 	it->c = *p, it->len = 1;
@@ -4604,7 +4630,7 @@
 	     for the *Message* buffer.  */
 	  for (i = 0; i < len; i += nbytes)
 	    {
-	      c = STRING_CHAR_AND_LENGTH (m + i, len - i, nbytes);
+	      c = string_char_and_length (m + i, len - i, &nbytes);
 	      work[0] = (SINGLE_BYTE_CHAR_P (c)
 			 ? c
 			 : multibyte_char_to_unibyte (c, Qnil));
@@ -9773,7 +9799,7 @@
       
       /* Get the next character.  */
       if (multibyte_p)
-	it.c = STRING_CHAR_AND_LENGTH (p, arrow_len, it.len);
+	it.c = string_char_and_length (p, arrow_len, &it.len);
       else
 	it.c = *p, it.len = 1;
       p += it.len;