Table of Contents

About

Searches key-value tuples, matching key and value with a needle and returns the key-value tuple in a list, where the head element is the key and the tail element is the value.

Comments

Error Handling

Remarks

Example Usage

Suppose that the key-value data contains:

string kvp = "data=empty&movement=off"

when calling the function with:

wasKeyValueGet("move", kvp);

the function will return the list:

[ "movement", "off" ];

Code

This script was tested and works on OpenSim version 0.7.4!

///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0    //
///////////////////////////////////////////////////////////////////////////
list wasKeyValueFindTuple(string needle, string kvp) {
    list a = ["!","\"","#","%","'","(",")","*","+",",","-",".","/",":",";",
        "<",">","?","@","[","\\","]","^","_","`","{","|","}","~", " "];
    list dVars = llParseString2List(kvp, ["&"], []);
    do {
        list kv = llParseString2List(llList2String(dVars, 0), ["="], []);
        list x = llParseString2List(llList2String(kv, 0), a, []);
        list y = llParseString2List(llList2String(kv, 1), a, []);
        do {
            string m = llList2String(x, 0);
            if(llSubStringIndex(llToLower(m), llToLower(needle)) != -1) return kv;
            x = llDeleteSubList(x, 0, 0);
            m = llList2String(y, 0);
            if(llSubStringIndex(llToLower(m), llToLower(needle)) != -1) return kv;
            y = llDeleteSubList(y, 0, 0);
        } while(llGetListLength(x) && llGetListLength(y));
        dVars = llDeleteSubList(dVars, 0, 0);
    } while(llGetListLength(dVars));
    return [ "", "" ];
}