diff options
| author | Kenichi Handa | 1998-10-24 01:17:09 +0000 |
|---|---|---|
| committer | Kenichi Handa | 1998-10-24 01:17:09 +0000 |
| commit | 9b703a38c632537810ab1cbe1ff93befa17849c7 (patch) | |
| tree | 50479ece70f12bc3e4ef7afc4ab931ee731ff952 /src | |
| parent | 7c3d2af25691dc41d9ea3f0e86ce5b57aaee71fd (diff) | |
| download | emacs-9b703a38c632537810ab1cbe1ff93befa17849c7.tar.gz emacs-9b703a38c632537810ab1cbe1ff93befa17849c7.zip | |
(Fbase64_decode_region): Pay attention to the byte
combining problem.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fns.c | 22 |
1 files changed, 16 insertions, 6 deletions
| @@ -2966,6 +2966,7 @@ If the region can't be decoded, return nil and don't modify the buffer.") | |||
| 2966 | char *decoded; | 2966 | char *decoded; |
| 2967 | int old_pos = PT; | 2967 | int old_pos = PT; |
| 2968 | int decoded_length; | 2968 | int decoded_length; |
| 2969 | int inserted_chars; | ||
| 2969 | 2970 | ||
| 2970 | validate_region (&beg, &end); | 2971 | validate_region (&beg, &end); |
| 2971 | 2972 | ||
| @@ -2987,19 +2988,28 @@ If the region can't be decoded, return nil and don't modify the buffer.") | |||
| 2987 | 2988 | ||
| 2988 | /* Now we have decoded the region, so we insert the new contents | 2989 | /* Now we have decoded the region, so we insert the new contents |
| 2989 | and delete the old. (Insert first in order to preserve markers.) */ | 2990 | and delete the old. (Insert first in order to preserve markers.) */ |
| 2990 | SET_PT (beg); | 2991 | /* We insert two spaces, then insert the decoded text in between |
| 2992 | them, at last, delete those extra two spaces. This is to avoid | ||
| 2993 | byte combining. */ | ||
| 2994 | TEMP_SET_PT_BOTH (XFASTINT (beg), ibeg); | ||
| 2995 | insert_1_both (" ", 2, 2, 0, 1, 0); | ||
| 2996 | TEMP_SET_PT_BOTH (XFASTINT (beg) + 1, ibeg + 1); | ||
| 2991 | insert (decoded, decoded_length); | 2997 | insert (decoded, decoded_length); |
| 2992 | del_range_byte (ibeg + decoded_length, iend + decoded_length, 1); | 2998 | inserted_chars = PT - (XFASTINT (beg) + 1); |
| 2999 | del_range_both (PT, PT_BYTE, XFASTINT (end) + inserted_chars + 2, | ||
| 3000 | iend + decoded_length + 2, 1); | ||
| 3001 | del_range_both (XFASTINT (beg), ibeg, XFASTINT (beg) + 1, ibeg + 1, 1); | ||
| 3002 | inserted_chars = PT - XFASTINT (beg); | ||
| 2993 | 3003 | ||
| 2994 | /* If point was outside of the region, restore it exactly; else just | 3004 | /* If point was outside of the region, restore it exactly; else just |
| 2995 | move to the beginning of the region. */ | 3005 | move to the beginning of the region. */ |
| 2996 | if (old_pos >= XFASTINT (end)) | 3006 | if (old_pos >= XFASTINT (end)) |
| 2997 | old_pos += decoded_length - length; | 3007 | old_pos += inserted_chars - (XFASTINT (end) - XFASTINT (beg)); |
| 2998 | else if (old_pos > beg) | 3008 | else if (old_pos > XFASTINT (beg)) |
| 2999 | old_pos = beg; | 3009 | old_pos = XFASTINT (beg); |
| 3000 | SET_PT (old_pos); | 3010 | SET_PT (old_pos); |
| 3001 | 3011 | ||
| 3002 | return make_number (decoded_length); | 3012 | return make_number (inserted_chars); |
| 3003 | } | 3013 | } |
| 3004 | 3014 | ||
| 3005 | DEFUN ("base64-decode-string", Fbase64_decode_string, Sbase64_decode_string, | 3015 | DEFUN ("base64-decode-string", Fbase64_decode_string, Sbase64_decode_string, |