Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
82 lines
2.0 KiB
VimL
82 lines
2.0 KiB
VimL
function! SpaceVim#api#iconv#bytes#import() abort
|
|
return s:bytes
|
|
endfunction
|
|
|
|
let s:bytes = {}
|
|
|
|
function! s:bytes.tobytes(v) abort
|
|
if type(a:v) == type([])
|
|
return a:v
|
|
elseif type(a:v) == type('')
|
|
return self.str2bytes(a:v)
|
|
else
|
|
throw "Can't convert to bytes"
|
|
endif
|
|
endfunction
|
|
|
|
function! s:bytes.str2bytes(str) abort
|
|
return map(range(len(a:str)), 'char2nr(a:str[v:val])')
|
|
endfunction
|
|
|
|
function! s:bytes.bytes2str(bytes) abort
|
|
return eval('"' . join(map(copy(a:bytes), 'printf(''\x%02x'', v:val)'), '') . '"')
|
|
endfunction
|
|
|
|
function! s:bytes.bytes2hex(bytes) abort
|
|
return join(map(copy(a:bytes), 'printf("%02x", v:val)'), '')
|
|
endfunction
|
|
|
|
function! s:bytes.hex2bytes(hex) abort
|
|
return map(split(a:hex, '..\zs'), 'str2nr(v:val, 16)')
|
|
endfunction
|
|
|
|
function! s:bytes.lines2bytes(lines) abort
|
|
let bytes = []
|
|
let first = 1
|
|
for line in a:lines
|
|
if !first
|
|
call add(bytes, 10)
|
|
endif
|
|
let first = 0
|
|
call extend(bytes, map(range(len(line)), 'line[v:val] ==# "\n" ? 0 : char2nr(line[v:val])'))
|
|
endfor
|
|
return bytes
|
|
endfunction
|
|
|
|
function! s:bytes.bytes2lines(bytes) abort
|
|
let table = map(range(256), 'printf(''\x%02x'', v:val == 0 ? 10 : v:val)')
|
|
let lines = []
|
|
let start = 0
|
|
while start < len(a:bytes)
|
|
let end = index(a:bytes, 10, start)
|
|
if end == -1
|
|
let end = len(a:bytes)
|
|
endif
|
|
let line = eval('"' . join(map(range(start, end - 1), 'table[a:bytes[v:val]]'), '') . '"')
|
|
call add(lines, line)
|
|
if end == len(a:bytes) - 1
|
|
call add(lines, '')
|
|
endif
|
|
let start = end + 1
|
|
endwhile
|
|
return lines
|
|
endfunction
|
|
|
|
function! s:bytes.readfile(filename) abort
|
|
try
|
|
let lines = readfile(a:filename, 'b')
|
|
catch /^Vim\%((\a\+)\)\=:E484:/
|
|
throw "Can't read file"
|
|
endtry
|
|
let bytes = self.lines2bytes(lines)
|
|
return bytes
|
|
endfunction
|
|
|
|
function! s:bytes.writefile(bytes, filename) abort
|
|
let lines = self.bytes2lines(a:bytes)
|
|
if writefile(lines, a:filename, 'b') != 0
|
|
throw "Can't write file"
|
|
endif
|
|
endfunction
|
|
|