mirror of
https://github.com/inkarkat/vim-ingo-library.git
synced 2026-05-29 11:18:51 +02:00
Add ingo#regexp#deconstruct#RemoveMultis()
This commit is contained in:
@@ -27,6 +27,24 @@ function! ingo#regexp#deconstruct#RemovePositionAtoms( pattern )
|
||||
return substitute(a:pattern, '\%(\%(^\|[^\\]\)\%(\\\\\)*\\\)\@<!\%(\\\%([\^<>]\|_\^\|_\$\|%[\^$V#]\|%[<>]\?''.\|%[<>]\?\d\+[lcv]\)\|[\^$]\)', '', 'g')
|
||||
endfunction
|
||||
|
||||
function! ingo#regexp#deconstruct#RemoveMultis( pattern )
|
||||
"******************************************************************************
|
||||
"* PURPOSE:
|
||||
" Remove multi items (*, \+, etc.) that signify the multiplicity of the
|
||||
" previous atom from a:pattern.
|
||||
"* ASSUMPTIONS / PRECONDITIONS:
|
||||
" Does not consider "very magic" (/\v)-style syntax. If you may have this,
|
||||
" convert via ingo#regexp#magic#Normalize() first.
|
||||
"* EFFECTS / POSTCONDITIONS:
|
||||
" None.
|
||||
"* INPUTS:
|
||||
" a:pattern regular expression
|
||||
"* RETURN VALUES:
|
||||
" Modified a:pattern with multi items removed.
|
||||
"******************************************************************************
|
||||
return substitute(a:pattern, '\%(\%(^\|[^\\]\)\%(\\\\\)*\\\)\@<!\%(\*\|\\[+=?]\|\\{-\?\d*,\?\d*}\|\\@\%(>\|=\|!\|<=\|<!\)\)', '', 'g')
|
||||
endfunction
|
||||
|
||||
let s:specialLookup = {
|
||||
\ 'e': "\e",
|
||||
\ 't': "\t",
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
" Test removing multis.
|
||||
|
||||
call vimtest#StartTap()
|
||||
call vimtap#Plan(4)
|
||||
|
||||
call vimtap#Is(ingo#regexp#deconstruct#RemoveMultis('foobar'), 'foobar', 'no multis')
|
||||
call vimtap#Is(ingo#regexp#deconstruct#RemoveMultis('fo\{1,10}bar\? .* l\([aeiou]\)ll\1'), 'fobar . l\([aeiou]\)ll\1', '\? * \{} multis')
|
||||
call vimtap#Is(ingo#regexp#deconstruct#RemoveMultis('fo\{-}ba\{-1}r\{-,10} \{2,7}x\\{1,2}'), 'fobar x\\{1,2}', 'various \{} multis')
|
||||
call vimtap#Is(ingo#regexp#deconstruct#RemoveMultis('a\@<= foo\(bar\)\@=bar'), 'a foo\(bar\)bar', '\@= multis')
|
||||
|
||||
call vimtest#Quit()
|
||||
Reference in New Issue
Block a user