ParseString2List

From Second Life Wiki
Revision as of 00:23, 18 September 2007 by Strife Onizuka (talk | contribs) (New page: <div id="box"> == Function: list ParseString2List(string {{LSL Param|src}}, list {{LSL Param|separators}}, list {{LSL Param|spacers}}, integer {{LSL Param|ParseStringKe...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Function: list ParseString2List(string src, list separators, list spacers, integer ParseStringKeepNulls);

Returns a list that is src broken into a list, discarding separators, keeping spacers.

if ParseStringKeepNulls == FALSE

Same as llParseString2List, but not limited to 8 spacers or separators.

Thus substitute a call to the llParseString2List function by a call to ParseString2List whenever you have more than 8 separators or more than 8 spacers.

if ParseStringKeepNulls != FALSE

Same as llParseStringKeepNulls, but not limited to 8 spacers or separators.

Thus substitute a call to the llParseStringKeepNulls function by a call to ParseString2List whenever you have more than 8 separators or more than 8 spacers.

list ParseString2List(string src, list separators, list spacers, integer ParseStringKeepNulls)
{//works just like llParseString2List and llParseStringKeepNulls but without 
 //the limits on spacers or separators
    list keys;
    integer i = spacers != [];
    integer offset;
    integer test;
    list out;
    string p;
    while(i)
        if((p = llList2String(spacers, i = ~-i)))
        {
            if(~(test = llSubStringIndex(src, p)))
            {
                if(~(offset = llListFindList(out, (list)p)))
                {
                    out = llDeleteSubList(out, offset, offset);
                    keys = llDeleteSubList(keys, -~(offset << 1), (-~offset) << 1);
                }
                keys = test + ((~i) + keys);
                out = p + out;
            }
        }
    for(i = separators != [];i;)
        if((p = llList2String(separators, i = ~-i)))
        {
            if(~(test = llSubStringIndex(src, p)))
            {
                if(~(offset = llListFindList(out, (list)p)))
                {
                    out = llDeleteSubList(out, offset, offset);
                    keys = llDeleteSubList(keys, -~(offset << 1), (-~offset) << 1);
                }
                keys = test + (i + keys);
                out = p + out;
            }
        }
    out = [];
    offset = 0;
    while(keys)
    {
        list t = llList2List(llListSort(keys, 2, TRUE), 0, 1);
        integer r = llListFindList(keys, t);
        if((i = llList2Integer(t, 0)) < offset)
            keys = llDeleteSubList(keys, r, -~r);
        else
        {
            if(offset != i || ParseStringKeepNulls)
                out += llDeleteSubString(src, i - offset, -1);
            if(0x80000000 & test = llList2Integer(t, 1))
                out += p = llList2String(spacers, ~test);
            else
                p = llList2String(separators, test);
            src = llDeleteSubString(src, 0, ~(offset - (i += llStringLength(p))));
            offset = i;
            if(~(test = llSubStringIndex(src, p)))
                keys = llListReplaceList(keys, (list)(test + offset), r, r);
            else
                keys = llDeleteSubList(keys, r, -~r);
        }
    }
    if(src != "" || ParseStringKeepNulls)
        return out + src;
    return out;
}//Strife Onizuka