Merges the key-value pair string kvp
with the parameters from a string data
and returns the result as a key-value pair.
data
and kvp
string in description format, eg variable_1=value_1&variable_2=value_2
.kvp
, changing or adding the new variables from data
.Suppose that the object description is:
toggle=on&target=<0,0,1>&sound=off
and that we call the function as:
llSetObjectDesc(wasKeyValueMerge("toggle=off&sound=on", llGetObjectDesc()));
then the object description will be updated to:
toggle=off&target=<0,0,1>&sound=on
Suppose that the object description is:
toggle=on&target=<0,0,1>&sound=off
and that we call the function as:
llSetObjectDesc(wasKeyValueMerge("toggle=off&special=k", llGetObjectDesc()));
then the object description will be updated to:
toggle=off&target=<0,0,1>&sound=off&special=k
The extra key-value pair special=k
gets added.
=
and &
symbols.wasKeyValueMergeTuple
.x
and z
off the left listx
can be found in right, assign the value of right to z
.x=z
+ recurse at 3.x=z
by &
.[ a b c d e f ] | [ x z a e r t ] [ c d e f | x z r t ] | a=e [ e f | x z r t ] | a=e c=d [ | x z r t ] | a=e c=d e=f // --- left = 0, left := right, right := 0 [ x z r t | ] | a=e c=d e=f [ r t | ] | a=e c=d e=f x=z [ | ] | a=e c=d e=f x=z r=t
/////////////////////////////////////////////////////////////////////////// // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // /////////////////////////////////////////////////////////////////////////// list wasKeyValueMergeTuple(list left, list right) { if(llGetListLength(left) == 0 && llGetListLength(right) == 0) return []; if(llGetListLength(left) == 0) { left = right; right = []; } string lk = llList2String(left, 0); left = llDeleteSubList(left, 0, 0); string lv = llList2String(left, 0); left = llDeleteSubList(left, 0, 0); integer x = llListFindList(right, (list)lk); if(x != -1) { lv = llList2String(right, x+1); right = llDeleteSubList(right, x, x+1); } return [lk + "=" + lv] + wasKeyValueMergeTuple(left, right); } /////////////////////////////////////////////////////////////////////////// // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // /////////////////////////////////////////////////////////////////////////// string wasKeyValueMerge(string kva, string kvb) { return llDumpList2String( wasKeyValueMergeTuple( llParseString2List(kva, ["=", "&"], []), llParseString2List(kvb, ["=", "&"], []) ) ,"&" ); }