aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
diff options
context:
space:
mode:
authoridb2008-12-12 11:50:12 +0000
committeridb2008-12-12 11:50:12 +0000
commit1ba76f57ba13ae59f518ecf9ba2319dd54b7a934 (patch)
tree9c6a480ca944f17852f7826a05feec1355e64f82 /OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
parentapparently opensim only works if secure_inventory_server = true, who (diff)
downloadopensim-SC_OLD-1ba76f57ba13ae59f518ecf9ba2319dd54b7a934.zip
opensim-SC_OLD-1ba76f57ba13ae59f518ecf9ba2319dd54b7a934.tar.gz
opensim-SC_OLD-1ba76f57ba13ae59f518ecf9ba2319dd54b7a934.tar.bz2
opensim-SC_OLD-1ba76f57ba13ae59f518ecf9ba2319dd54b7a934.tar.xz
Made the casting of stings to floats more robust and work more like SL.
Added some more tests that casts previously failed on. Fixes Mantis #2789
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs32
1 files changed, 18 insertions, 14 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
index 65b1b5c..da40995 100644
--- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
@@ -1363,7 +1363,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
1363 1363
1364 public static explicit operator double(LSLString s) 1364 public static explicit operator double(LSLString s)
1365 { 1365 {
1366 return Convert.ToDouble(s.m_string); 1366 return new LSLFloat(s).value;
1367 } 1367 }
1368 1368
1369 public static explicit operator LSLInteger(LSLString s) 1369 public static explicit operator LSLInteger(LSLString s)
@@ -1401,7 +1401,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
1401 1401
1402 public static implicit operator LSLFloat(LSLString s) 1402 public static implicit operator LSLFloat(LSLString s)
1403 { 1403 {
1404 return new LSLFloat(Convert.ToDouble(s.m_string)); 1404 return new LSLFloat(s);
1405 } 1405 }
1406 1406
1407 public static implicit operator list(LSLString s) 1407 public static implicit operator list(LSLString s)
@@ -1737,7 +1737,21 @@ namespace OpenSim.Region.ScriptEngine.Shared
1737 1737
1738 public LSLFloat(string s) 1738 public LSLFloat(string s)
1739 { 1739 {
1740 this.value = double.Parse(s); 1740 Regex r = new Regex("^ *(\\+|-)?([0-9]+\\.?[0-9]*|\\.[0-9]+)([eE](\\+|-)?[0-9]+)?");
1741 Match m = r.Match(s);
1742 string v = m.Groups[0].Value;
1743
1744 v = v.Trim();
1745
1746 if (v == String.Empty || v == null)
1747 v = "0.0";
1748 else
1749 if (!v.Contains(".") && !v.ToLower().Contains("e"))
1750 v = v + ".0";
1751 else
1752 if (v.EndsWith("."))
1753 v = v + "0";
1754 this.value = double.Parse(v, System.Globalization.NumberStyles.Float);
1741 } 1755 }
1742 1756
1743 #endregion 1757 #endregion
@@ -1783,17 +1797,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
1783 1797
1784 static public explicit operator LSLFloat(string s) 1798 static public explicit operator LSLFloat(string s)
1785 { 1799 {
1786 Regex r = new Regex("^[ ]*-?[0-9]*\\.?[0-9]*[eE]?-?[0-9]*"); 1800 return new LSLFloat(s);
1787 Match m = r.Match(s);
1788 string v = m.Groups[0].Value;
1789
1790 while (v.Length > 0 && v.Substring(0, 1) == " ")
1791 v = v.Substring(1);
1792
1793 if (v == String.Empty)
1794 v = "0";
1795
1796 return new LSLFloat(double.Parse(v));
1797 } 1801 }
1798 1802
1799 public static implicit operator list(LSLFloat f) 1803 public static implicit operator list(LSLFloat f)