comparison src/coding.c @ 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 8f6f64cc1f08
children 84032a5b04a9
comparison
equal deleted inserted replaced
20615:ddb1eec37783 20616:b382c9ca6c39
3465 &consumed) 3465 &consumed)
3466 : decode_coding (coding, begp, buf, shrunk_len_byte, buflen, 3466 : decode_coding (coding, begp, buf, shrunk_len_byte, buflen,
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)
3474 { 3480 {
3475 opoint += ZV - zv_before; 3481 opoint += ZV - zv_before;
3537 { 3543 {
3538 /* Since we have to call Lisp functions which assume target text 3544 /* Since we have to call Lisp functions which assume target text
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);
3553 set_buffer_internal (old); 3559 set_buffer_internal (old);
3554 return unbind_to (count, result); 3560 return unbind_to (count, result);
3555 } 3561 }
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
3571 if (encodep) 3578 if (encodep)
3572 len = encoding_buffer_size (coding, endp - begp); 3579 len = encoding_buffer_size (coding, endp - begp);
3585 buf + head_skip + produced, 3592 buf + head_skip + produced,
3586 tail_skip); 3593 tail_skip);
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
3593 DEFUN ("decode-coding-region", Fdecode_coding_region, Sdecode_coding_region, 3605 DEFUN ("decode-coding-region", Fdecode_coding_region, Sdecode_coding_region,
3594 3, 3, "r\nzCoding system: ", 3606 3, 3, "r\nzCoding system: ",