# HG changeset patch # User Kenichi Handa # Date 909191829 0 # Node ID 0154f51c56d8882db2e8fcf06fa083fade67875e # Parent 28c62eea9ae72397b95cbc346496d8da403069bc (Fbase64_decode_region): Pay attention to the byte combining problem. diff -r 28c62eea9ae7 -r 0154f51c56d8 src/fns.c --- a/src/fns.c Thu Oct 22 06:44:53 1998 +0000 +++ b/src/fns.c Sat Oct 24 01:17:09 1998 +0000 @@ -2966,6 +2966,7 @@ char *decoded; int old_pos = PT; int decoded_length; + int inserted_chars; validate_region (&beg, &end); @@ -2987,19 +2988,28 @@ /* Now we have decoded the region, so we insert the new contents and delete the old. (Insert first in order to preserve markers.) */ - SET_PT (beg); + /* We insert two spaces, then insert the decoded text in between + them, at last, delete those extra two spaces. This is to avoid + byte combining. */ + TEMP_SET_PT_BOTH (XFASTINT (beg), ibeg); + insert_1_both (" ", 2, 2, 0, 1, 0); + TEMP_SET_PT_BOTH (XFASTINT (beg) + 1, ibeg + 1); insert (decoded, decoded_length); - del_range_byte (ibeg + decoded_length, iend + decoded_length, 1); + inserted_chars = PT - (XFASTINT (beg) + 1); + del_range_both (PT, PT_BYTE, XFASTINT (end) + inserted_chars + 2, + iend + decoded_length + 2, 1); + del_range_both (XFASTINT (beg), ibeg, XFASTINT (beg) + 1, ibeg + 1, 1); + inserted_chars = PT - XFASTINT (beg); /* If point was outside of the region, restore it exactly; else just move to the beginning of the region. */ if (old_pos >= XFASTINT (end)) - old_pos += decoded_length - length; - else if (old_pos > beg) - old_pos = beg; + old_pos += inserted_chars - (XFASTINT (end) - XFASTINT (beg)); + else if (old_pos > XFASTINT (beg)) + old_pos = XFASTINT (beg); SET_PT (old_pos); - return make_number (decoded_length); + return make_number (inserted_chars); } DEFUN ("base64-decode-string", Fbase64_decode_string, Sbase64_decode_string,