Skip to content

Instantly share code, notes, and snippets.

@mattn
Last active March 21, 2016 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattn/5300623003d6d2c4563d to your computer and use it in GitHub Desktop.
Save mattn/5300623003d6d2c4563d to your computer and use it in GitHub Desktop.
diff --git a/runtime/tools/unicode.vim b/runtime/tools/unicode.vim
index dfe9cef..4b4e56f 100644
--- a/runtime/tools/unicode.vim
+++ b/runtime/tools/unicode.vim
@@ -32,8 +32,8 @@ func! ParseFoldProps()
if line !~ '^#' && line !~ '^\s*$'
let l = split(line, '\s*;\s*', 1)
if len(l) != 4
- echoerr 'Found ' . len(l) . ' items in line ' . lnum . ', expected 4'
- return
+ echoerr 'Found ' . len(l) . ' items in line ' . lnum . ', expected 4'
+ return
endif
call add(s:foldprops, l)
endif
@@ -50,8 +50,8 @@ func! ParseWidthProps()
if line !~ '^#' && line !~ '^\s*$'
let l = split(line, '\s*;\s*', 1)
if len(l) != 2
- echoerr 'Found ' . len(l) . ' items in line ' . lnum . ', expected 2'
- return
+ echoerr 'Found ' . len(l) . ' items in line ' . lnum . ', expected 2'
+ return
endif
call add(s:widthprops, l)
endif
@@ -72,18 +72,18 @@ func! BuildCaseTable(name, index)
let n = ('0x' . p[0]) + 0
let nl = ('0x' . p[a:index]) + 0
if start >= 0 && add == nl - n && (step == 0 || n - end == step)
- " continue with same range.
- let step = n - end
- let end = n
+ " continue with same range.
+ let step = n - end
+ let end = n
else
- if start >= 0
- " produce previous range
- call Range(ranges, start, end, step, add)
- endif
- let start = n
- let end = n
- let step = 0
- let add = nl - n
+ if start >= 0
+ " produce previous range
+ call Range(ranges, start, end, step, add)
+ endif
+ let start = n
+ let end = n
+ let step = 0
+ let add = nl - n
endif
endif
endfor
@@ -115,18 +115,18 @@ func! BuildFoldTable()
let n = ('0x' . p[0]) + 0
let nl = ('0x' . p[2]) + 0
if start >= 0 && add == nl - n && (step == 0 || n - end == step)
- " continue with same range.
- let step = n - end
- let end = n
+ " continue with same range.
+ let step = n - end
+ let end = n
else
- if start >= 0
- " produce previous range
- call Range(ranges, start, end, step, add)
- endif
- let start = n
- let end = n
- let step = 0
- let add = nl - n
+ if start >= 0
+ " produce previous range
+ call Range(ranges, start, end, step, add)
+ endif
+ let start = n
+ let end = n
+ let step = 0
+ let add = nl - n
endif
endif
endfor
@@ -160,15 +160,15 @@ func! BuildCombiningTable()
if p[2] == 'Mn' || p[2] == 'Mc' || p[2] == 'Me'
let n = ('0x' . p[0]) + 0
if start >= 0 && end + 1 == n
- " continue with same range.
- let end = n
+ " continue with same range.
+ let end = n
else
- if start >= 0
- " produce previous range
- call add(ranges, printf("\t{0x%04x, 0x%04x},", start, end))
- endif
- let start = n
- let end = n
+ if start >= 0
+ " produce previous range
+ call add(ranges, printf("\t{0x%04x, 0x%04x},", start, end))
+ endif
+ let start = n
+ let end = n
endif
endif
endfor
@@ -197,42 +197,42 @@ func! BuildWidthTable(pattern, tableName)
for p in s:widthprops
if p[1][0] =~ a:pattern
if p[0] =~ '\.\.'
- " It is a range. we don't check for composing char then.
- let rng = split(p[0], '\.\.')
- if len(rng) != 2
- echoerr "Cannot parse range: '" . p[0] . "' in width table"
- endif
- let n = ('0x' . rng[0]) + 0
- let n_last = ('0x' . rng[1]) + 0
+ " It is a range. we don't check for composing char then.
+ let rng = split(p[0], '\.\.')
+ if len(rng) != 2
+ echoerr "Cannot parse range: '" . p[0] . "' in width table"
+ endif
+ let n = ('0x' . rng[0]) + 0
+ let n_last = ('0x' . rng[1]) + 0
else
- let n = ('0x' . p[0]) + 0
- let n_last = n
+ let n = ('0x' . p[0]) + 0
+ let n_last = n
endif
" Find this char in the data table.
while 1
- let dn = ('0x' . s:dataprops[dataidx][0]) + 0
- if dn >= n
- break
- endif
- let dataidx += 1
+ let dn = ('0x' . s:dataprops[dataidx][0]) + 0
+ if dn >= n
+ break
+ endif
+ let dataidx += 1
endwhile
if dn != n && n_last == n
- echoerr "Cannot find character " . n . " in data table"
+ echoerr "Cannot find character " . n . " in data table"
endif
" Only use the char when it's not a composing char.
" But use all chars from a range.
let dp = s:dataprops[dataidx]
if n_last > n || (dp[2] != 'Mn' && dp[2] != 'Mc' && dp[2] != 'Me')
- if start >= 0 && end + 1 == n
- " continue with same range.
- else
- if start >= 0
- " produce previous range
- call add(ranges, printf("\t{0x%04x, 0x%04x},", start, end))
- endif
- let start = n
- endif
- let end = n_last
+ if start >= 0 && end + 1 == n
+ " continue with same range.
+ else
+ if start >= 0
+ " produce previous range
+ call add(ranges, printf("\t{0x%04x, 0x%04x},", start, end))
+ endif
+ let start = n
+ endif
+ let end = n_last
endif
endif
endfor
@@ -253,23 +253,30 @@ endfunc
" Build the amoji width table in a new buffer.
func! BuildEmojiTable(pattern, tableName)
- let ranges = []
- for line in map(filter(filter(getline(1, '$'), 'v:val=~"^[1-9]"'), 'v:val=~a:pattern'), 'matchstr(v:val,"^\\S\\+")')
+ let tokens = []
+ let lines = map(filter(filter(getline(1, '$'), 'v:val=~"^[1-9]"'), 'v:val=~a:pattern'), 'matchstr(v:val,"^\\S\\+")')
+ for n in range(len(lines))
+ let line = lines[n]
let token = split(line, '\.\.')
if len(token) == 1
call add(token, token[0])
endif
- call add(ranges, printf("\t{0x%04x, 0x%04x},", "0x".token[0], "0x".token[1]))
+ if len(tokens) > 0 && ("0x" . token[0]) - 1 == ("0x" . tokens[-1][1])
+ let tokens[-1][1] = token[1]
+ else
+ call add(tokens, token)
+ endif
endfor
+ let ranges = map(tokens, 'printf(" {0x%04x, 0x%04x},", "0x".v:val[0], "0x".v:val[1])')
" New buffer to put the result in.
new
exe "file " . a:tableName
- call setline(1, " static struct interval " . a:tableName . "[] =")
- call setline(2, " {")
+ call setline(1, "static struct interval " . a:tableName . "[] =")
+ call setline(2, "{")
call append('$', ranges)
call setline('$', getline('$')[:-2]) " remove last comma
- call setline(line('$') + 1, " };")
+ call setline(line('$') + 1, "};")
wincmd p
endfunc
@@ -316,4 +323,4 @@ call BuildWidthTable('A', 'ambiguous')
edit http://www.unicode.org/Public/emoji/3.0/emoji-data.txt
" Build the emoji table. Ver. 1.0 - 6.0
-call BuildEmojiTable('; Emoji\s\+# [1-6]\.[0-9]', 'emoji')
+call BuildEmojiTable('; Emoji\s\+# [1-6]\.[0-9]', 'emoji_tab')
diff --git a/src/mbyte.c b/src/mbyte.c
index c670a06..d4aa73f 100644
--- a/src/mbyte.c
+++ b/src/mbyte.c
@@ -1258,8 +1258,7 @@ static struct interval emoji_tab[] =
{0x26bd, 0x26be},
{0x26c4, 0x26c5},
{0x26c8, 0x26c8},
- {0x26ce, 0x26ce},
- {0x26cf, 0x26cf},
+ {0x26ce, 0x26cf},
{0x26d1, 0x26d1},
{0x26d3, 0x26d4},
{0x26e9, 0x26ea},
@@ -1268,9 +1267,7 @@ static struct interval emoji_tab[] =
{0x26fd, 0x26fd},
{0x2702, 0x2702},
{0x2705, 0x2705},
- {0x2708, 0x2709},
- {0x270a, 0x270b},
- {0x270c, 0x270d},
+ {0x2708, 0x270d},
{0x270f, 0x270f},
{0x2712, 0x2712},
{0x2714, 0x2714},
@@ -1302,8 +1299,7 @@ static struct interval emoji_tab[] =
{0x1f004, 0x1f004},
{0x1f0cf, 0x1f0cf},
{0x1f170, 0x1f171},
- {0x1f17e, 0x1f17e},
- {0x1f17f, 0x1f17f},
+ {0x1f17e, 0x1f17f},
{0x1f18e, 0x1f18e},
{0x1f191, 0x1f19a},
{0x1f1e6, 0x1f1ff},
@@ -1325,29 +1321,7 @@ static struct interval emoji_tab[] =
{0x1f4f9, 0x1f4fc},
{0x1f500, 0x1f53d},
{0x1f550, 0x1f567},
- {0x1f5fb, 0x1f5ff},
- {0x1f600, 0x1f600},
- {0x1f601, 0x1f610},
- {0x1f611, 0x1f611},
- {0x1f612, 0x1f614},
- {0x1f615, 0x1f615},
- {0x1f616, 0x1f616},
- {0x1f617, 0x1f617},
- {0x1f618, 0x1f618},
- {0x1f619, 0x1f619},
- {0x1f61a, 0x1f61a},
- {0x1f61b, 0x1f61b},
- {0x1f61c, 0x1f61e},
- {0x1f61f, 0x1f61f},
- {0x1f620, 0x1f625},
- {0x1f626, 0x1f627},
- {0x1f628, 0x1f62b},
- {0x1f62c, 0x1f62c},
- {0x1f62d, 0x1f62d},
- {0x1f62e, 0x1f62f},
- {0x1f630, 0x1f633},
- {0x1f634, 0x1f634},
- {0x1f635, 0x1f640},
+ {0x1f5fb, 0x1f640},
{0x1f645, 0x1f64f},
{0x1f680, 0x1f6c5}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment