4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: When 'enc' is "utf-16" and 'fenc' is "utf-8" writing a file does
12 conversion while none should be done. (Yukihiro Nakadaira) When
13 'fenc' is empty the file is written as utf-8 instead of utf-16.
14 Solution: Do proper comparison of encodings, taking into account that all
15 Unicode values for 'enc' use utf-8 internally.
19 *** ../vim-7.2.244/src/fileio.c 2009-07-29 18:05:57.000000000 +0200
20 --- src/fileio.c 2009-07-29 17:04:06.000000000 +0200
24 static linenr_T readfile_linenr __ARGS((linenr_T linecnt, char_u *p, char_u *endp));
25 static int ucs2bytes __ARGS((unsigned c, char_u **pp, int flags));
26 ! static int same_encoding __ARGS((char_u *a, char_u *b));
27 static int get_fio_flags __ARGS((char_u *ptr));
28 static char_u *check_for_bom __ARGS((char_u *p, long size, int *lenp, int flags));
29 static int make_bom __ARGS((char_u *buf, char_u *name));
32 static linenr_T readfile_linenr __ARGS((linenr_T linecnt, char_u *p, char_u *endp));
33 static int ucs2bytes __ARGS((unsigned c, char_u **pp, int flags));
34 ! static int need_conversion __ARGS((char_u *fenc));
35 static int get_fio_flags __ARGS((char_u *ptr));
36 static char_u *check_for_bom __ARGS((char_u *p, long size, int *lenp, int flags));
37 static int make_bom __ARGS((char_u *buf, char_u *name));
43 ! * Conversion is required when the encoding of the file is different
44 ! * from 'encoding' or 'encoding' is UTF-16, UCS-2 or UCS-4 (requires
45 ! * conversion to UTF-8).
48 ! converted = (*fenc != NUL && !same_encoding(p_enc, fenc));
49 ! if (converted || enc_unicode != 0)
52 /* "ucs-bom" means we need to check the first bytes of the file
57 ! * Conversion may be required when the encoding of the file is different
58 ! * from 'encoding' or 'encoding' is UTF-16, UCS-2 or UCS-4.
61 ! converted = need_conversion(fenc);
65 /* "ucs-bom" means we need to check the first bytes of the file
71 ! * The file needs to be converted when 'fileencoding' is set and
72 ! * 'fileencoding' differs from 'encoding'.
74 ! converted = (*fenc != NUL && !same_encoding(p_enc, fenc));
77 * Check if UTF-8 to UCS-2/4 or Latin1 conversion needs to be done. Or
82 ! * Check if the file needs to be converted.
84 ! converted = need_conversion(fenc);
87 * Check if UTF-8 to UCS-2/4 or Latin1 conversion needs to be done. Or
93 ! * Return TRUE if "a" and "b" are the same 'encoding'.
94 ! * Ignores difference between "ansi" and "latin1", "ucs-4" and "ucs-4be", etc.
103 ! if (STRCMP(a, b) == 0)
105 ! f = get_fio_flags(a);
106 ! return (f != 0 && get_fio_flags(b) == f);
114 ! * Return TRUE if file encoding "fenc" requires conversion from or to
118 ! need_conversion(fenc)
125 ! if (*fenc == NUL || STRCMP(p_enc, fenc) == 0)
126 ! same_encoding = TRUE;
129 ! /* Ignore difference between "ansi" and "latin1", "ucs-4" and
130 ! * "ucs-4be", etc. */
131 ! enc_flags = get_fio_flags(p_enc);
132 ! fenc_flags = get_fio_flags(fenc);
133 ! same_encoding = (enc_flags != 0 && fenc_flags == enc_flags);
137 ! /* Specified encoding matches with 'encoding'. This requires
138 ! * conversion when 'encoding' is Unicode but not UTF-8. */
139 ! return enc_unicode != 0;
142 ! /* Encodings differ. However, conversion is not needed when 'enc' is any
143 ! * Unicode encoding and the file is UTF-8. */
144 ! return !(enc_utf8 && fenc_flags == FIO_UTF8);
148 *** ../vim-7.2.244/src/version.c 2009-07-29 18:05:57.000000000 +0200
149 --- src/version.c 2009-07-29 18:20:08.000000000 +0200
153 { /* Add new patch number below this line */
159 An actual excerpt from a classified section of a city newspaper:
160 "Illiterate? Write today for free help!"
162 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
163 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
164 \\\ download, build and distribute -- http://www.A-A-P.org ///
165 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///