#  (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and
#  distribute this software is granted provided this copyright notice appears in
#  all copies. This software is provided "as is" without express or implied
#  warranty, and with no claim as to its suitability for any purpose.

rule split ( string separator )
{
    local result ;
    local s = $(string) ;
    
    while $(s)
    {
        local match = [ SUBST $(s) ^(.*)$(separator)(.*) $1 $2 ] ;
        
        local tail = $(match[2]) ;
        tail ?= $(s) ;

        result = $(tail) $(result) ;
        s = $(match[1]) ;
    }
    return $(result) ;
}

rule __test__ ( )
{
    import assert ;
    
    assert.result a b c : split "a/b/c" / ;
    assert.result a b c : split "/a/b/c" / ;
    assert.result "" a b c : split "//a/b/c" / ;
    assert.result a "" b c : split "/a//b/c" / ;
    assert.result a "" b c "" : split "/a//b/c/" / ;
    assert.result a "" b c "" "" : split "/a//b/c//" / ;
}
