To: vim-dev@vim.org Subject: Patch 6.2.448 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.2.448 (after 6.2.427) Problem: Mac: conversion done when 'termencoding' differs from 'encoding' fails when pasting a longer text. Solution: Check for an incomplete sequence at the end of the chunk to be converted. (Eckehard Berns) Files: src/mbyte.c *** ../vim-6.2.447/src/mbyte.c Sun Apr 4 16:30:29 2004 --- src/mbyte.c Sun Apr 4 22:25:08 2004 *************** *** 5284,5289 **** --- 5417,5423 ---- * vcp->vc_type must have been initialized to CONV_NONE. * Note: cannot be used for conversion from/to ucs-2 and ucs-4 (will use utf-8 * instead). + * Afterwards invoke with "from" and "to" equal to NULL to cleanup. * Return FAIL when conversion is not supported, OK otherwise. */ int *************** *** 5371,5376 **** --- 5505,5512 ---- return OK; } + #if defined(FEAT_GUI) || defined(AMIGA) || defined(WIN3264) \ + || defined(MSDOS) || defined(PROTO) /* * Do conversion on typed input characters in-place. * The input and output are not NUL terminated! *************** *** 5384,5389 **** --- 5520,5526 ---- { return convert_input_safe(ptr, len, maxlen, NULL, NULL); } + #endif /* * Like convert_input(), but when there is an incomplete byte sequence at the *************** *** 5428,5452 **** } #if defined(MACOS_X) ! static char_u *mac_string_convert __ARGS((char_u *ptr, int len, int *lenp, int fail_on_error, CFStringEncoding from, CFStringEncoding to)); /* ! * A Mac version of string_convert() for special cases. */ static char_u * ! mac_string_convert(ptr, len, lenp, fail_on_error, from, to) char_u *ptr; int len; int *lenp; int fail_on_error; CFStringEncoding from; CFStringEncoding to; { char_u *retval, *d; CFStringRef cfstr; int buflen, in, out, l, i; cfstr = CFStringCreateWithBytes(NULL, ptr, len, from, 0); if (cfstr == NULL) return NULL; if (to == kCFStringEncodingUTF8) --- 5565,5601 ---- } #if defined(MACOS_X) ! static char_u *mac_string_convert __ARGS((char_u *ptr, int len, int *lenp, int fail_on_error, CFStringEncoding from, CFStringEncoding to, int *unconvlenp)); /* ! * A Mac version of string_convert_ext() for special cases. */ static char_u * ! mac_string_convert(ptr, len, lenp, fail_on_error, from, to, unconvlenp) char_u *ptr; int len; int *lenp; int fail_on_error; CFStringEncoding from; CFStringEncoding to; + int *unconvlenp; { char_u *retval, *d; CFStringRef cfstr; int buflen, in, out, l, i; + if (unconvlenp != NULL) + *unconvlenp = 0; cfstr = CFStringCreateWithBytes(NULL, ptr, len, from, 0); + /* When conversion failed, try excluding bytes from the end, helps when + * there is an incomplete byte sequence. Only do up to 6 bytes to avoid + * looping a long time when there really is something unconvertable. */ + while (cfstr == NULL && unconvlenp != NULL && len > 1 && *unconvlenp < 6) + { + --len; + ++*unconvlenp; + cfstr = CFStringCreateWithBytes(NULL, ptr, len, from, 0); + } if (cfstr == NULL) return NULL; if (to == kCFStringEncodingUTF8) *************** *** 5626,5650 **** case CONV_MAC_LATIN1: retval = mac_string_convert(ptr, len, lenp, vcp->vc_fail, kCFStringEncodingMacRoman, ! kCFStringEncodingISOLatin1); break; case CONV_LATIN1_MAC: retval = mac_string_convert(ptr, len, lenp, vcp->vc_fail, kCFStringEncodingISOLatin1, ! kCFStringEncodingMacRoman); break; case CONV_MAC_UTF8: retval = mac_string_convert(ptr, len, lenp, vcp->vc_fail, kCFStringEncodingMacRoman, ! kCFStringEncodingUTF8); break; case CONV_UTF8_MAC: retval = mac_string_convert(ptr, len, lenp, vcp->vc_fail, kCFStringEncodingUTF8, ! kCFStringEncodingMacRoman); break; # endif --- 5775,5803 ---- case CONV_MAC_LATIN1: retval = mac_string_convert(ptr, len, lenp, vcp->vc_fail, kCFStringEncodingMacRoman, ! kCFStringEncodingISOLatin1, ! unconvlenp); break; case CONV_LATIN1_MAC: retval = mac_string_convert(ptr, len, lenp, vcp->vc_fail, kCFStringEncodingISOLatin1, ! kCFStringEncodingMacRoman, ! unconvlenp); break; case CONV_MAC_UTF8: retval = mac_string_convert(ptr, len, lenp, vcp->vc_fail, kCFStringEncodingMacRoman, ! kCFStringEncodingUTF8, ! unconvlenp); break; case CONV_UTF8_MAC: retval = mac_string_convert(ptr, len, lenp, vcp->vc_fail, kCFStringEncodingUTF8, ! kCFStringEncodingMacRoman, ! unconvlenp); break; # endif *** ../vim-6.2.447/src/version.c Sun Apr 4 16:35:39 2004 --- src/version.c Mon Apr 5 19:39:04 2004 *************** *** 639,640 **** --- 639,642 ---- { /* Add new patch number below this line */ + /**/ + 448, /**/ -- In his lifetime van Gogh painted 486 oil paintings. Oddly enough, 8975 of them are to be found in the United States. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ Project leader for A-A-P -- http://www.A-A-P.org /// \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html /// -- Error:015 - Unable to exit Windows. Try the door. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ Project leader for A-A-P -- http://www.A-A-P.org /// \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///