]>
Commit | Line | Data |
---|---|---|
e4816a84 ER |
1 | To: vim-dev@vim.org |
2 | Subject: Patch 7.2.245 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=UTF-8 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 7.2.245 | |
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. | |
16 | Files: src/fileio.c | |
17 | ||
18 | ||
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 | |
21 | *************** | |
22 | *** 134,140 **** | |
23 | #ifdef FEAT_MBYTE | |
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)); | |
30 | --- 134,140 ---- | |
31 | #ifdef FEAT_MBYTE | |
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)); | |
38 | *************** | |
39 | *** 1043,1055 **** | |
40 | } | |
41 | ||
42 | /* | |
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). | |
46 | */ | |
47 | fio_flags = 0; | |
48 | ! converted = (*fenc != NUL && !same_encoding(p_enc, fenc)); | |
49 | ! if (converted || enc_unicode != 0) | |
50 | { | |
51 | ||
52 | /* "ucs-bom" means we need to check the first bytes of the file | |
53 | --- 1043,1054 ---- | |
54 | } | |
55 | ||
56 | /* | |
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. | |
59 | */ | |
60 | fio_flags = 0; | |
61 | ! converted = need_conversion(fenc); | |
62 | ! if (converted) | |
63 | { | |
64 | ||
65 | /* "ucs-bom" means we need to check the first bytes of the file | |
66 | *************** | |
67 | *** 3969,3978 **** | |
68 | fenc = buf->b_p_fenc; | |
69 | ||
70 | /* | |
71 | ! * The file needs to be converted when 'fileencoding' is set and | |
72 | ! * 'fileencoding' differs from 'encoding'. | |
73 | */ | |
74 | ! converted = (*fenc != NUL && !same_encoding(p_enc, fenc)); | |
75 | ||
76 | /* | |
77 | * Check if UTF-8 to UCS-2/4 or Latin1 conversion needs to be done. Or | |
78 | --- 3968,3976 ---- | |
79 | fenc = buf->b_p_fenc; | |
80 | ||
81 | /* | |
82 | ! * Check if the file needs to be converted. | |
83 | */ | |
84 | ! converted = need_conversion(fenc); | |
85 | ||
86 | /* | |
87 | * Check if UTF-8 to UCS-2/4 or Latin1 conversion needs to be done. Or | |
88 | *************** | |
89 | *** 5502,5521 **** | |
90 | } | |
91 | ||
92 | /* | |
93 | ! * Return TRUE if "a" and "b" are the same 'encoding'. | |
94 | ! * Ignores difference between "ansi" and "latin1", "ucs-4" and "ucs-4be", etc. | |
95 | */ | |
96 | static int | |
97 | ! same_encoding(a, b) | |
98 | ! char_u *a; | |
99 | ! char_u *b; | |
100 | { | |
101 | ! int f; | |
102 | ||
103 | ! if (STRCMP(a, b) == 0) | |
104 | ! return TRUE; | |
105 | ! f = get_fio_flags(a); | |
106 | ! return (f != 0 && get_fio_flags(b) == f); | |
107 | } | |
108 | ||
109 | /* | |
110 | --- 5500,5536 ---- | |
111 | } | |
112 | ||
113 | /* | |
114 | ! * Return TRUE if file encoding "fenc" requires conversion from or to | |
115 | ! * 'encoding'. | |
116 | */ | |
117 | static int | |
118 | ! need_conversion(fenc) | |
119 | ! char_u *fenc; | |
120 | { | |
121 | ! int same_encoding; | |
122 | ! int enc_flags; | |
123 | ! int fenc_flags; | |
124 | ||
125 | ! if (*fenc == NUL || STRCMP(p_enc, fenc) == 0) | |
126 | ! same_encoding = TRUE; | |
127 | ! else | |
128 | ! { | |
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); | |
134 | ! } | |
135 | ! if (same_encoding) | |
136 | ! { | |
137 | ! /* Specified encoding matches with 'encoding'. This requires | |
138 | ! * conversion when 'encoding' is Unicode but not UTF-8. */ | |
139 | ! return enc_unicode != 0; | |
140 | ! } | |
141 | ! | |
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); | |
145 | } | |
146 | ||
147 | /* | |
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 | |
150 | *************** | |
151 | *** 678,679 **** | |
152 | --- 678,681 ---- | |
153 | { /* Add new patch number below this line */ | |
154 | + /**/ | |
155 | + 245, | |
156 | /**/ | |
157 | ||
158 | -- | |
159 | An actual excerpt from a classified section of a city newspaper: | |
160 | "Illiterate? Write today for free help!" | |
161 | ||
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 /// |