diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs index 092d9c2b99..a440cf3a6e 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs @@ -1162,265 +1162,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine dstarr[i + dststart] = srcstr[i + srcstart]; } - /** - * @brief Implement osParseJSON() so we return an array to the script. - * No coherent example of its use in scripts on web found. - * see http://www.json.org/ for more details on JSON - */ - private static LSL_List nullList = new LSL_List(new object[0]); - public new XMR_Array osParseJSON(string json) - { - XMR_Array dict = new XMR_Array(this); - int idx = ParseJSON(dict, nullList, json, 0); - while(idx < json.Length) - { - if(json[idx] > ' ') - throw new Exception("left-over json " + json); - idx++; - } - return dict; - } - - private static int ParseJSON(XMR_Array dict, LSL_List keys, string json, int idx) - { - char c; - - while((c = json[idx++]) <= ' ') - { - } - switch(c) - { - - // '{' ':' [ ',' ':' ... ] '}' - case '{': - do - { - string key = ParseJSONString(json, ref idx); - while((c = json[idx++]) <= ' ') - { - } - if(c != ':') - throw new Exception("missing : after key"); - idx = ParseJSON(dict, ParseJSONKeyAdd(keys, key), json, idx); - while((c = json[idx++]) <= ' ') - { - } - } while(c == ','); - if(c != '}') - throw new Exception("missing , or } after value"); - break; - - - // '[' [ ',' ... ] ']' - case '[': - int index = 0; - do - { - object key = index++; - idx = ParseJSON(dict, ParseJSONKeyAdd(keys, key), json, idx); - while((c = json[idx++]) <= ' ') - { - } - } while(c == ','); - if(c != ']') - throw new Exception("missing , or ] after value"); - break; - - - // '"''"' - case '"': - { - --idx; - string val = ParseJSONString(json, ref idx); - dict.SetByKey(keys, val); - break; - } - // true false null - case 't': - if(json.Substring(idx, 3) != "rue") - throw new Exception("bad true in json"); - idx += 3; - dict.SetByKey(keys, 1); - break; - - case 'f': - if(json.Substring(idx, 4) != "alse") - throw new Exception("bad false in json"); - idx += 4; - dict.SetByKey(keys, 0); - break; - - case 'n': - if(json.Substring(idx, 3) != "ull") - throw new Exception("bad null in json"); - idx += 3; - dict.SetByKey(keys, null); - break; - - // otherwise assume it's a number - default: - { - --idx; - object val = ParseJSONNumber(json, ref idx); - dict.SetByKey(keys, val); - break; - } - } - return idx; - } - - // Given the key for a whole array, create a key for a given element of the array - private static LSL_List ParseJSONKeyAdd(LSL_List oldkeys, object key) - { - int oldkeyslen = oldkeys.Length; - object[] array = oldkeys.Data; - Array.Resize(ref array, oldkeyslen + 1); - array[oldkeyslen] = key; - return new LSL_List(array); - } - - // Parse out a JSON string - private static string ParseJSONString(string json, ref int idx) - { - char c; - - while((c = json[idx++]) <= ' ') - { - } - if(c != '"') - throw new Exception("bad start of json string"); - - StringBuilder sb = new StringBuilder(); - while((c = json[idx++]) != '"') - { - if(c == '\\') - { - c = json[idx++]; - switch(c) - { - case 'b': - c = '\b'; - break; - - case 'f': - c = '\f'; - break; - - case 'n': - c = '\n'; - break; - - case 'r': - c = '\r'; - break; - - case 't': - c = '\t'; - break; - - case 'u': - c = (char)Int32.Parse(json.Substring(idx, 4), - System.Globalization.NumberStyles.HexNumber); - idx += 4; - break; - - default: - break; - } - } - sb.Append(c); - } - return sb.ToString(); - } - - // Parse out a JSON number - private static object ParseJSONNumber(string json, ref int idx) - { - char c; - - while((c = json[idx++]) <= ' ') - { - } - - bool expneg = false; - bool isneg = false; - int decpt = -1; - int expon = 0; - int ival = 0; - double dval = 0; - - if(c == '-') - { - isneg = true; - c = json[idx++]; - } - if((c < '0') || (c > '9')) - throw new Exception("bad json number"); - - while((c >= '0') && (c <= '9')) - { - dval *= 10; - ival *= 10; - dval += c - '0'; - ival += c - '0'; - c = '\0'; - if(idx < json.Length) - c = json[idx++]; - } - if(c == '.') - { - decpt = 0; - c = '\0'; - if(idx < json.Length) - c = json[idx++]; - while((c >= '0') && (c <= '9')) - { - dval *= 10; - dval += c - '0'; - decpt++; - c = '\0'; - if(idx < json.Length) - c = json[idx++]; - } - } - if((c == 'e') || (c == 'E')) - { - if(decpt < 0) - decpt = 0; - c = json[idx++]; - if(c == '-') - expneg = true; - if((c == '-') || (c == '+')) - c = json[idx++]; - while((c >= '0') && (c <= '9')) - { - expon *= 10; - expon += c - '0'; - c = '\0'; - if(idx < json.Length) - c = json[idx++]; - } - if(expneg) - expon = -expon; - } - - if(c != 0) - --idx; - if(decpt < 0) - { - if(isneg) - ival = -ival; - return ival; - } - else - { - if(isneg) - dval = -dval; - dval *= Math.Pow(10, expon - decpt); - return dval; - } - } - /** * @brief Exception-related runtime calls. */