ap schrieb:
> 
> On Oct 18, 10:29 pm, Andy Wokula <[EMAIL PROTECTED]> wrote:
>> Ok, for now I'll go with this:
>>
>> func! SplitMatch(str, pat)
>>     let matpos = match(a:str, a:pat)
>>     let reslist = []
>>     let mendp = 0   " match (after) end position
>>     while matpos >= 0
>>         let mendp = matchend(a:str, a:pat, mendp)
>>         call add(reslist, strpart(a:str, matpos, mendp-matpos))
>>         let matpos = match(a:str, a:pat, mendp)
>>     endwhile
>>     return reslist
>> endfunc
>>
>> --
>> Andy
> 
> Try SplitMatch("aba","b*").

Oops.

> I would go for
> 
> let res= []
> call substitute(str,pat,'\=add(res,submatch(0))','g')
> 
> 1000 ways to kill a cow.
> 
> -ap

Thx, that looks good.
Hmm, I already used that to solve my problem (call a function on all the
substitute() matches), but just didn't see a general solution.

Nevertheless a bugfix:

func! SplitMatch(str, pat)
    let matpos = match(a:str, a:pat)
    let reslist = []
    let mendp = 0   " match (after) end position
    while matpos >= 0
        let mendp = matchend(a:str, a:pat, mendp)
        call add(reslist, strpart(a:str, matpos, mendp-matpos))
        if mendp == matpos
            let mendp += 1
        endif
        let matpos = match(a:str, a:pat, mendp)
    endwhile
    return reslist
endfunc

Still buggy:
    :echo SplitMatch("aba", ".*")
    ['aba', '']

I'll drop that function.

-- 
Andy

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui