From dc2017b3d92a5ca09e4b3d599902284cc282d20e Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 5 Jun 2023 21:35:22 +0100 Subject: [PATCH] cosmetics on lsl json --- .../Shared/Api/Implementation/LSL_Api.cs | 68 +++++++++++-------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 8c1f934e8d..66bad794b5 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -17670,17 +17670,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api private static string ListToJson(object o) { - if (o is LSL_Float || o is double) + if (o is double od) { - if (o is not double float_val) - float_val = ((LSL_Float)o).value; - - if(double.IsInfinity(float_val)) + if(double.IsInfinity(od)) return "\"Inf\""; - if(double.IsNaN(float_val)) + if(double.IsNaN(od)) return "\"NaN\""; - return ((LSL_Float)float_val).ToString(); + return od.ToString(); + } + if (o is LSL_Float olf) + { + if (double.IsInfinity(olf.value)) + return "\"Inf\""; + if (double.IsNaN(olf.value)) + return "\"NaN\""; + + return olf.value.ToString(); } if (o is LSL_Integer LSL_Integero) { @@ -17692,40 +17698,46 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } if (o is LSL_Rotation LSL_Rotationo) { - StringBuilder sb = new(128); - sb.Append('\"'); - sb.Append(LSL_Rotationo.ToString()); - sb.Append('\"'); - return sb.ToString(); + return $"\"{LSL_Rotationo}\""; } if (o is LSL_Vector LSL_Vectoro) { - StringBuilder sb = new(128); - sb.Append('\"'); - sb.Append(LSL_Vectoro.ToString()); - sb.Append('\"'); - return sb.ToString(); + return $"\"{LSL_Vectoro}\""; } - if (o is LSL_String || o is string) + if (o is string str) { - if (o is not string str) - str = ((LSL_String)o).m_string; - - if(str == ScriptBaseClass.JSON_TRUE || str == "true") - return "true"; - if(str == ScriptBaseClass.JSON_FALSE ||str == "false") - return "false"; - if(str == ScriptBaseClass.JSON_NULL || str == "null") - return "null"; str = str.Trim(); - if(str.Length == 0) + if (str.Length == 0) return "\"\""; if (str[0] == '{') return str; if (str[0] == '[') return str; + if (str.Equals(ScriptBaseClass.JSON_TRUE) || str.Equals("true")) + return "true"; + if(str.Equals(ScriptBaseClass.JSON_FALSE) || str.Equals("false")) + return "false"; + if(str.Equals(ScriptBaseClass.JSON_NULL) || str.Equals("null")) + return "null"; return EscapeForJSON(str, true); } + if (o is LSL_String olstr) + { + string lstr = olstr.m_string.Trim(); + if (lstr.Length == 0) + return "\"\""; + if (lstr[0] == '{') + return lstr; + if (lstr[0] == '[') + return lstr; + if (lstr.Equals(ScriptBaseClass.JSON_TRUE) || lstr.Equals( "true")) + return "true"; + if (lstr.Equals(ScriptBaseClass.JSON_FALSE) || lstr.Equals("false")) + return "false"; + if (lstr.Equals(ScriptBaseClass.JSON_NULL) || lstr.Equals( "null")) + return "null"; + return EscapeForJSON(lstr, true); + } throw new IndexOutOfRangeException(); }