Deletes a key k
and its corresponding value from a key-value pair.
Suppose the object's description is set to:
sound=on&time=now&position=<1,0,0>
When the function is called with:
llSetObjectDesc(wasKeyValueDelete("position", llGetObjectDesc()));
the object's description will be updated to:
sound=on&time=now
/////////////////////////////////////////////////////////////////////////// // Copyright (C) 2014 Wizardry and Steamworks - License: CC BY 2.0 // /////////////////////////////////////////////////////////////////////////// string wasKeyValueDelete(string k, string data) { if(llStringLength(data) == 0) return ""; if(llStringLength(k) == 0) return ""; integer i = llListFindList( llList2ListStrided( llParseString2List(data, ["&", "="], []), 0, -1, 2 ), [ k ]); if(i != -1) return llDumpList2String( llDeleteSubList( llParseString2List(data, ["&"], []), i, i), "&"); return data; }
/////////////////////////////////////////////////////////////////////////// // Copyright (C) 2014 Wizardry and Steamworks - License: CC BY 2.0 // /////////////////////////////////////////////////////////////////////////// /// <summary> /// Deletes a key-value pair from a string referenced by a key. /// </summary> /// <param name="key">the key to search for</param> /// <param name="data">the key-value data segment</param> /// <returns>a key-value pair string</returns> private static string wasKeyValueDelete(string key, string data) { List<string> output = new List<string>(); foreach (string tuples in data.Split('&')) { string[] tuple = tuples.Split('='); if (!tuple.Length.Equals(2)) { continue; } if (tuple[0].Equals(key, StringComparison.Ordinal)) { continue; } output.Add(string.Join("=", tuple)); } return string.Join("&", output.ToArray()); }
########################################################################### ## Copyright (C) Wizardry and Steamworks 2015 - License: CC BY 2.0 ## ########################################################################### function wasKeyValueDelete($key, $data) { $data = explode("&", $data); $data = array_filter( array_combine( array_map( function($o) { return array_shift(explode("=", $o)); }, $data ), array_map( function($o) { return array_pop(explode("=", $o)); }, $data ) ) ); if (array_key_exists($key, $data)) { unset($data[$key]); } array_walk($data, function(&$value, $key) { $value = $key."=".$value; } ); return implode('&', $data); }