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.
needle
as a string.kvp
as a string.key
is the head element and value
is the tail element.needle
cannot be matched.Ord
, the function splits on ASCII tokens only. That means that for a hay of kvp=love♥you
, a call such as wasKeyValueFindTuple("love", kvp)
, the function will fail to find the tuple.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" ];
/////////////////////////////////////////////////////////////////////////// // 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 [ "", "" ]; }