Encodes a list of variables and values to the key-value pair format.
[ "variable_1", "value_1", "variable_2", "value_2" ]
.variable_1=value_1&variable_2=value_2
.When called with:
wasKeyValueEncode(["sound", "off", "time", "1365161334"]);
the function will return the string:
sound=off&time=1365161334
/////////////////////////////////////////////////////////////////////////// // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // /////////////////////////////////////////////////////////////////////////// string wasKeyValueEncode(list data) { integer i = llGetListLength(data); if (i % 2 != 0 || i == 0) return ""; --i; do { data = llListInsertList( llDeleteSubList( data, i-1, i ), [ llList2String(data, i-1) + "=" + llList2String(data, i) ], i-1 ); i -= 2; } while(i > 0); return llDumpList2String(data, "&"); }
/////////////////////////////////////////////////////////////////////////// // Copyright (C) 2014 Wizardry and Steamworks - License: CC BY 2.0 // /////////////////////////////////////////////////////////////////////////// /// <summary> /// Serialises a dictionary to key-value data. /// </summary> /// <param name="data">a dictionary</param> /// <returns>a key-value data encoded string</returns> private static string wasKeyValueEncode(Dictionary<string, string> data) { List<string> output = new List<string>(); foreach (KeyValuePair<string, string> tuple in data) { output.Add(string.Join("=", new [] {tuple.Key, tuple.Value})); } return string.Join("&", output.ToArray()); }
########################################################################### ## Copyright (C) Wizardry and Steamworks 2014 - License: CC BY 2.0 ## ########################################################################### function wasKeyValueEncode($data) { array_walk($data, function(&$value, $key) { $value = $key."=".$value; } ); return implode('&', $data); }