\f
/* 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 *));
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). */
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;
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;
for (nchars = 0; rest > 0; ++nchars)
{
- STRING_CHAR_AND_LENGTH (p, rest, len);
+ string_char_and_length (p, rest, &len);
rest -= len, p += len;
}
}
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;
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);
- 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
{
- 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
{
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;
{
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;
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));
/* 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;