namespace split

namespace split, an additional command for working with namespaces, splits a qualified name into its components.

See Also

ycl ns split
An implementation of namespace split, as described below.

Description

namespace split can be trivially implemented using ycl regsplit:

package require {ycl string}
namespace import [yclprefix]::string::regsplit

proc nssplit ns {
    regsplit ::* ns
    lmap {val delim} $ns[set ns {}] {
        lindex $val
    }
}

example:

puts [nssplit {::one::two three::::four::five::}]
# -> {} one {two three} four five {}