Mercurial > vim
comparison runtime/tools/unicode.vim @ 2063:1378bc45ebe5 v7.2.348
updated for version 7.2.348
Problem: Unicode double-width characters are not up-to date.
Solution: Produce the double-width table like the others.
author | Bram Moolenaar <bram@zimbu.org> |
---|---|
date | Wed, 27 Jan 2010 18:29:26 +0100 |
parents | d5867fd6b2b7 |
children | c9a5d51c9161 |
comparison
equal
deleted
inserted
replaced
2062:dae4cd29a0b7 | 2063:1378bc45ebe5 |
---|---|
185 call setline('$', getline('$')[:-2]) " remove last comma | 185 call setline('$', getline('$')[:-2]) " remove last comma |
186 call setline(line('$') + 1, " };") | 186 call setline(line('$') + 1, " };") |
187 wincmd p | 187 wincmd p |
188 endfunc | 188 endfunc |
189 | 189 |
190 " Build the ambiguous table in a new buffer. | 190 " Build the double width or ambiguous width table in a new buffer. |
191 " Uses s:widthprops and s:dataprops. | 191 " Uses s:widthprops and s:dataprops. |
192 func! BuildAmbiguousTable() | 192 func! BuildWidthTable(pattern, tableName) |
193 let start = -1 | 193 let start = -1 |
194 let end = -1 | 194 let end = -1 |
195 let ranges = [] | 195 let ranges = [] |
196 let dataidx = 0 | 196 let dataidx = 0 |
197 for p in s:widthprops | 197 for p in s:widthprops |
198 if p[1][0] == 'A' | 198 if p[1][0] =~ a:pattern |
199 let n = ('0x' . p[0]) + 0 | 199 if p[0] =~ '\.\.' |
200 " It is a range. we don't check for composing char then. | |
201 let rng = split(p[0], '\.\.') | |
202 if len(rng) != 2 | |
203 echoerr "Cannot parse range: '" . p[0] . "' in width table" | |
204 endif | |
205 let n = ('0x' . rng[0]) + 0 | |
206 let n_last = ('0x' . rng[1]) + 0 | |
207 else | |
208 let n = ('0x' . p[0]) + 0 | |
209 let n_last = n | |
210 endif | |
200 " Find this char in the data table. | 211 " Find this char in the data table. |
201 while 1 | 212 while 1 |
202 let dn = ('0x' . s:dataprops[dataidx][0]) + 0 | 213 let dn = ('0x' . s:dataprops[dataidx][0]) + 0 |
203 if dn >= n | 214 if dn >= n |
204 break | 215 break |
205 endif | 216 endif |
206 let dataidx += 1 | 217 let dataidx += 1 |
207 endwhile | 218 endwhile |
208 if dn != n | 219 if dn != n && n_last == n |
209 echoerr "Cannot find character " . n . " in data table" | 220 echoerr "Cannot find character " . n . " in data table" |
210 endif | 221 endif |
211 " Only use the char when it's not a composing char. | 222 " Only use the char when it's not a composing char. |
223 " But use all chars from a range. | |
212 let dp = s:dataprops[dataidx] | 224 let dp = s:dataprops[dataidx] |
213 if dp[2] != 'Mn' && dp[2] != 'Mc' && dp[2] != 'Me' | 225 if n_last > n || (dp[2] != 'Mn' && dp[2] != 'Mc' && dp[2] != 'Me') |
214 if start >= 0 && end + 1 == n | 226 if start >= 0 && end + 1 == n |
215 " continue with same range. | 227 " continue with same range. |
216 let end = n | |
217 else | 228 else |
218 if start >= 0 | 229 if start >= 0 |
219 " produce previous range | 230 " produce previous range |
220 call add(ranges, printf("\t{0x%04x, 0x%04x},", start, end)) | 231 call add(ranges, printf("\t{0x%04x, 0x%04x},", start, end)) |
221 endif | 232 endif |
222 let start = n | 233 let start = n |
223 if p[0] =~ '\.\.' | 234 endif |
224 let end = ('0x' . substitute(p[0], '.*\.\.', '', '')) + 0 | 235 let end = n_last |
225 else | |
226 let end = n | |
227 endif | |
228 endif | |
229 endif | 236 endif |
230 endif | 237 endif |
231 endfor | 238 endfor |
232 if start >= 0 | 239 if start >= 0 |
233 call add(ranges, printf("\t{0x%04x, 0x%04x},", start, end)) | 240 call add(ranges, printf("\t{0x%04x, 0x%04x},", start, end)) |
234 endif | 241 endif |
235 | 242 |
236 " New buffer to put the result in. | 243 " New buffer to put the result in. |
237 new | 244 new |
238 file ambiguous | 245 exe "file " . a:tableName |
239 call setline(1, " static struct interval ambiguous[] =") | 246 call setline(1, " static struct interval " . a:tableName . "[] =") |
240 call setline(2, " {") | 247 call setline(2, " {") |
241 call append('$', ranges) | 248 call append('$', ranges) |
242 call setline('$', getline('$')[:-2]) " remove last comma | 249 call setline('$', getline('$')[:-2]) " remove last comma |
243 call setline(line('$') + 1, " };") | 250 call setline(line('$') + 1, " };") |
244 wincmd p | 251 wincmd p |
274 edit http://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt | 281 edit http://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt |
275 | 282 |
276 " Parse each line, create a list of lists. | 283 " Parse each line, create a list of lists. |
277 call ParseWidthProps() | 284 call ParseWidthProps() |
278 | 285 |
279 " Build the ambiguous table. | 286 " Build the double width table. |
280 call BuildAmbiguousTable() | 287 call BuildWidthTable('[WF]', 'doublewidth') |
288 | |
289 " Build the ambiguous width table. | |
290 call BuildWidthTable('A', 'ambiguous') |