summaryrefslogtreecommitdiff
path: root/src/fns.c
diff options
context:
space:
mode:
authorKenichi Handa <handa@m17n.org>1998-10-24 01:17:09 +0000
committerKenichi Handa <handa@m17n.org>1998-10-24 01:17:09 +0000
commit9b703a38c632537810ab1cbe1ff93befa17849c7 (patch)
tree50479ece70f12bc3e4ef7afc4ab931ee731ff952 /src/fns.c
parent7c3d2af25691dc41d9ea3f0e86ce5b57aaee71fd (diff)
downloademacs-9b703a38c632537810ab1cbe1ff93befa17849c7.tar.gz
(Fbase64_decode_region): Pay attention to the byte
combining problem.
Diffstat (limited to 'src/fns.c')
-rw-r--r--src/fns.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/fns.c b/src/fns.c
index c802c5c803a..df1e063db4a 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -2966,6 +2966,7 @@ If the region can't be decoded, return nil and don't modify the buffer.")
char *decoded;
int old_pos = PT;
int decoded_length;
+ int inserted_chars;
validate_region (&beg, &end);
@@ -2987,19 +2988,28 @@ If the region can't be decoded, return nil and don't modify the buffer.")
/* 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,