Split function for ASL

Perl and other languages include a very useful utility function that splits a string into an array, breaking it up on a specified delimiter string.

ASL lacks such a feature, but does include the building blocks needed to provide one.

As is often the case, there are many ways of doing this - but here is one example..

START { .. eol } do {
        varbind = "Field 1::number two::three::This:wont:split";
        varlist = SPLIT(varbind, "::");
        foreach v (varlist) { print(v); }

}

SPLIT(str, delimiter) {
        input = str;
        delim = "";
        local var;
        local vars = list();
        rep(
                {
                        var: { .. delimiter }
                        do { vars += substring(var, 0, sizeof(var)-sizeof(delimiter)); }
                } | {
                        var: rep(word | fs)
                        do { vars += var; }
                }
        )?
        do { return vars; }
}

Scroll to Top