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:
parent
afd94396be
commit
713df46b80
@ -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'
|
||||
|
@ -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:
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user