/* Read a \-escape sequence, assuming we already read the `\'. */
static int
-read_escape (readcharfun)
+read_escape (readcharfun, stringp)
Lisp_Object readcharfun;
+ int stringp;
{
register int c = READCHAR;
switch (c)
case '\n':
return -1;
case ' ':
- return -1;
+ if (stringp)
+ return -1;
+ return ' ';
case 'M':
c = READCHAR;
error ("Invalid escape character syntax");
c = READCHAR;
if (c == '\\')
- c = read_escape (readcharfun);
+ c = read_escape (readcharfun, 0);
return c | meta_modifier;
case 'S':
error ("Invalid escape character syntax");
c = READCHAR;
if (c == '\\')
- c = read_escape (readcharfun);
+ c = read_escape (readcharfun, 0);
return c | shift_modifier;
case 'H':
error ("Invalid escape character syntax");
c = READCHAR;
if (c == '\\')
- c = read_escape (readcharfun);
+ c = read_escape (readcharfun, 0);
return c | hyper_modifier;
case 'A':
error ("Invalid escape character syntax");
c = READCHAR;
if (c == '\\')
- c = read_escape (readcharfun);
+ c = read_escape (readcharfun, 0);
return c | alt_modifier;
case 's':
error ("Invalid escape character syntax");
c = READCHAR;
if (c == '\\')
- c = read_escape (readcharfun);
+ c = read_escape (readcharfun, 0);
return c | super_modifier;
case 'C':
case '^':
c = READCHAR;
if (c == '\\')
- c = read_escape (readcharfun);
+ c = read_escape (readcharfun, 0);
if ((c & 0177) == '?')
return 0177 | c;
/* ASCII control chars are made from letters (both cases),
if (c < 0) return Fsignal (Qend_of_file, Qnil);
if (c == '\\')
- c = read_escape (readcharfun);
+ c = read_escape (readcharfun, 0);
else if (BASE_LEADING_CODE_P (c))
c = read_multibyte (c, readcharfun);
register char *p = read_buffer;
register char *end = read_buffer + read_buffer_size;
register int c;
+ /* Nonzero if we saw an escape sequence specifying
+ a multibyte character. */
+ int force_multibyte = 0;
+ /* Nonzero if we saw an escape sequence specifying
+ a single-byte character. */
+ int force_singlebyte = 0;
int cancel = 0;
+ int nchars;
while ((c = READCHAR) >= 0
&& c != '\"')
}
if (c == '\\')
{
- c = read_escape (readcharfun);
+ c = read_escape (readcharfun, 1);
if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_META)))
{
unsigned char workbuf[4];
int length;
length = non_ascii_char_to_string (c, workbuf, &str);
+ if (length > 1)
+ force_multibyte = 1;
if (p + length > end)
{
p += length;
continue;
}
+ else if (! ASCII_BYTE_P (c))
+ force_singlebyte = 1;
}
/* c is -1 if \ newline has just been seen */
if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel)
return make_number (0);
- if (read_pure)
- return make_pure_string (read_buffer, p - read_buffer,
- p - read_buffer);
- else if (! NILP (current_buffer->enable_multibyte_characters))
- return make_string (read_buffer, p - read_buffer);
+ if (force_singlebyte && force_multibyte)
+ error ("Multibyte and single-byte escapes in one string constant");
+
+ if (force_singlebyte)
+ nchars = p - read_buffer;
+ else if (! NILP (buffer_defaults.enable_multibyte_characters)
+ || force_multibyte)
+ nchars = chars_in_text (read_buffer, p - read_buffer);
else
- return make_unibyte_string (read_buffer, p - read_buffer);
+ nchars = p - read_buffer;
+
+ if (read_pure)
+ return make_pure_string (read_buffer, nchars, p - read_buffer);
+ return make_multibyte_string (read_buffer, nchars, p - read_buffer);
}
case '.':