1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-02 22:10:06 +08:00

Add replace for list api

This commit is contained in:
wsdjeg 2017-12-03 22:18:42 +08:00
parent afd94396be
commit 713df46b80
3 changed files with 15 additions and 2 deletions

View File

@ -16,8 +16,11 @@ function! s:update_log(log, summary, new_log) abort
let end = i
endif
endfor
return a:log . "\n" . a:new_log
if begin != -1 && end != -1
else
return a:log . "\n" . a:new_log
endif
endfunction
if !empty(s:log)
if $LINT == 'vader'

View File

@ -10,6 +10,7 @@ function! SpaceVim#api#data#list#get() abort
\ 'has' : '',
\ 'has_index' : '',
\ 'listpart' : '',
\ 'replace' : '',
\ },
\ "function('s:' . v:key)"
\ )
@ -101,4 +102,12 @@ function! s:has_index(list, index) abort
return 0 <= a:index && a:index < len(a:list)
endfunction
function! s:replace(list, begin, end, re_list)
if a:begin <= a:end && a:begin >= 0 && a:end < len(a:list)
return a:list[:a:begin - 1] + a:re_list + a:list[a:end + 1:]
else
return a:list
endif
endf
" vim:set et sw=2 cc=80:

View File

@ -11,3 +11,4 @@ Execute ( SpaceVim api: data#list ):
AssertEqual list.char_range('a', 'c'), ['a', 'b', 'c']
AssertEqual list.has(['a', 'c'], 'a'), 1
AssertEqual list.has_index(['a', 'c'], 1), 1
AssertEqual list.replace([1, 2, 3, 4, 5, 6, 7], 3, 5, [0, 0, 0, 0]), [1, 2, 3, 0, 0, 0, 0, 7]