Mercurial > emacs
changeset 20616:b382c9ca6c39
(code_convert_string): Maybe use make_unibyte_string.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 09 Jan 1998 23:05:12 +0000 |
parents | ddb1eec37783 |
children | 20957e3ca2f5 |
files | src/coding.c |
diffstat | 1 files changed, 17 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/coding.c Fri Jan 09 23:04:20 1998 +0000 +++ b/src/coding.c Fri Jan 09 23:05:12 1998 +0000 @@ -3467,7 +3467,13 @@ &consumed)); TEMP_SET_PT_BOTH (shrunk_beg, shrunk_beg_byte); - insert (buf, produced); + + if (encodep) + /* If we just encoded, treat the result as single-byte. */ + insert_1_both (buf, produced, produced, 0, 1, 0); + else + insert (buf, produced); + del_range_byte (PT_BYTE, PT_BYTE + shrunk_len_byte, 1); if (opoint >= end) @@ -3539,14 +3545,14 @@ is in a buffer, after setting a temporary buffer, call code_convert_region. */ int count = specpdl_ptr - specpdl; - int len = XSTRING (str)->size; + int len = XSTRING (str)->size_byte; Lisp_Object result; struct buffer *old = current_buffer; record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); temp_output_buffer_setup (" *code-converting-work*"); set_buffer_internal (XBUFFER (Vstandard_output)); - insert_from_string (str, 0, len, 0); + insert_from_string (str, 0, 0, XSTRING (str)->size, len, 0); code_convert_region (make_number (BEGV), make_number (ZV), coding, encodep); result = make_buffer_string (BEGV, ZV, 0); @@ -3556,15 +3562,16 @@ /* We may be able to shrink the conversion region. */ begp = XSTRING (str)->data; - endp = begp + XSTRING (str)->size; + endp = begp + XSTRING (str)->size_byte; shrink_conversion_area (&begp, &endp, coding, encodep); if (begp == endp) /* We need no conversion. */ return (NILP (nocopy) ? Fcopy_sequence (str) : str); + /* We assume that head_skip and tail_skip count single-byte characters. */ head_skip = begp - XSTRING (str)->data; - tail_skip = XSTRING (str)->size - head_skip - (endp - begp); + tail_skip = XSTRING (str)->size_byte - head_skip - (endp - begp); GCPRO1 (str); @@ -3587,6 +3594,11 @@ UNGCPRO; + if (encodep) + /* When encoding, the result is all single-byte characters. */ + return make_unibyte_string (buf, head_skip + produced + tail_skip); + + /* When decoding, count properly the number of chars in the string. */ return make_string (buf, head_skip + produced + tail_skip); }