aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/coding.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/coding.c b/src/coding.c
index 02199d5bf7a..11410f103c4 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -3467,7 +3467,13 @@ code_convert_region (b, e, coding, encodep)
3467 &consumed)); 3467 &consumed));
3468 3468
3469 TEMP_SET_PT_BOTH (shrunk_beg, shrunk_beg_byte); 3469 TEMP_SET_PT_BOTH (shrunk_beg, shrunk_beg_byte);
3470 insert (buf, produced); 3470
3471 if (encodep)
3472 /* If we just encoded, treat the result as single-byte. */
3473 insert_1_both (buf, produced, produced, 0, 1, 0);
3474 else
3475 insert (buf, produced);
3476
3471 del_range_byte (PT_BYTE, PT_BYTE + shrunk_len_byte, 1); 3477 del_range_byte (PT_BYTE, PT_BYTE + shrunk_len_byte, 1);
3472 3478
3473 if (opoint >= end) 3479 if (opoint >= end)
@@ -3539,14 +3545,14 @@ code_convert_string (str, coding, encodep, nocopy)
3539 is in a buffer, after setting a temporary buffer, call 3545 is in a buffer, after setting a temporary buffer, call
3540 code_convert_region. */ 3546 code_convert_region. */
3541 int count = specpdl_ptr - specpdl; 3547 int count = specpdl_ptr - specpdl;
3542 int len = XSTRING (str)->size; 3548 int len = XSTRING (str)->size_byte;
3543 Lisp_Object result; 3549 Lisp_Object result;
3544 struct buffer *old = current_buffer; 3550 struct buffer *old = current_buffer;
3545 3551
3546 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); 3552 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
3547 temp_output_buffer_setup (" *code-converting-work*"); 3553 temp_output_buffer_setup (" *code-converting-work*");
3548 set_buffer_internal (XBUFFER (Vstandard_output)); 3554 set_buffer_internal (XBUFFER (Vstandard_output));
3549 insert_from_string (str, 0, len, 0); 3555 insert_from_string (str, 0, 0, XSTRING (str)->size, len, 0);
3550 code_convert_region (make_number (BEGV), make_number (ZV), 3556 code_convert_region (make_number (BEGV), make_number (ZV),
3551 coding, encodep); 3557 coding, encodep);
3552 result = make_buffer_string (BEGV, ZV, 0); 3558 result = make_buffer_string (BEGV, ZV, 0);
@@ -3556,15 +3562,16 @@ code_convert_string (str, coding, encodep, nocopy)
3556 3562
3557 /* We may be able to shrink the conversion region. */ 3563 /* We may be able to shrink the conversion region. */
3558 begp = XSTRING (str)->data; 3564 begp = XSTRING (str)->data;
3559 endp = begp + XSTRING (str)->size; 3565 endp = begp + XSTRING (str)->size_byte;
3560 shrink_conversion_area (&begp, &endp, coding, encodep); 3566 shrink_conversion_area (&begp, &endp, coding, encodep);
3561 3567
3562 if (begp == endp) 3568 if (begp == endp)
3563 /* We need no conversion. */ 3569 /* We need no conversion. */
3564 return (NILP (nocopy) ? Fcopy_sequence (str) : str); 3570 return (NILP (nocopy) ? Fcopy_sequence (str) : str);
3565 3571
3572 /* We assume that head_skip and tail_skip count single-byte characters. */
3566 head_skip = begp - XSTRING (str)->data; 3573 head_skip = begp - XSTRING (str)->data;
3567 tail_skip = XSTRING (str)->size - head_skip - (endp - begp); 3574 tail_skip = XSTRING (str)->size_byte - head_skip - (endp - begp);
3568 3575
3569 GCPRO1 (str); 3576 GCPRO1 (str);
3570 3577
@@ -3587,6 +3594,11 @@ code_convert_string (str, coding, encodep, nocopy)
3587 3594
3588 UNGCPRO; 3595 UNGCPRO;
3589 3596
3597 if (encodep)
3598 /* When encoding, the result is all single-byte characters. */
3599 return make_unibyte_string (buf, head_skip + produced + tail_skip);
3600
3601 /* When decoding, count properly the number of chars in the string. */
3590 return make_string (buf, head_skip + produced + tail_skip); 3602 return make_string (buf, head_skip + produced + tail_skip);
3591} 3603}
3592 3604